Casey Flynn
Casey Flynn

Reputation: 14048

Javascript variable initialization syntax

I'm working with a javascript (Ext JS 4) project, and I came across this:

{
    init: function() {
        var me = this, desktopCfg;
        ...
    }
}

What exactly is being assigned to 'me' in this situation?

Upvotes: 2

Views: 930

Answers (2)

hackartist
hackartist

Reputation: 5264

the object this. the parser goes down the instructions and sees a comma separated list of the two instructions var me = this; desktopCfg; so the variable me gets the whole object that it is in.

Upvotes: 1

Quentin
Quentin

Reputation: 943967

This:

var me = this, desktopCfg;

Is equivalent to:

var me = this;
var desktopCfg;

as = has higher precedence than ,.

See also: the manual for var which has examples of this syntax.

Upvotes: 5

Related Questions