Here is a summary of the 4 rules defining the value of 'this':
1-Was the function called with the new keyword? If so, use that object.
2-Was the function called explicitly with call or apply? Use the passed in object.
3-Was the function called implicitly with the dot operator? Use the owning object, also called base object or context object, which means the object to the left of the dot of the function invocation.
4-If none of the above, the default rule applies, 'this' is the global object, except if in strict mode, 'this' is set to undefined.
Comments
Post a Comment