this

  • Updated

The this keyword is used in ScriptObject member functions to refer to the parent ScriptObject.

var x = { FirstName : "Joe", LastName : "Blow" };

x.GetFullName = function () { return this.FirstName + " " + this.LastName; };

var y = x.GetFullName();     // y == ‘Joe Blow’

The value of this resolves to null outside of ScriptObject members and initialization syntax.

The this keyword must always be explicitly referenced in a member method, to refer to the parent ScriptObject; that is, unlike C# no implicit reference to the parent object exists:

var x = { FirstName : "Joe", LastName : "Blow" };

// ERROR: cannot resolve FirstName and LastName below, without ‘this’ reference…

x.GetFullName = function () { return FirstName + " " + LastName; };

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.