Sunday, August 12, 2012

Nice post about "this" in JS

http://dailyjs.com/2012/06/18/js101-this/

Best part of the post:

When working with this, remember the following rules:
  • It’s set based on how a function is called: new MyConstructor ormyObject.method() will refer to an instance, while this inside a function refers to the global context
  • Strict mode causes this to evaluate to undefined instead of the global context inside functions
  • this can be referenced by a variable, and self is the conventionally used name

No comments: