|
|
|
|
|
by jestar_jokin
3933 days ago
|
|
For one, "this" could refer to anything at any time, depending on who invoked the enclosing function. function myFunc() {
console.log(this);
}
var myObj = {};
// this = window
myFunc();
// this = window
myFunc.apply(null, []);
// this = myObj
myFunc.apply(myObj, []);
myObj.myFunc = myFunc;
// this = myObj
myObj.myFunc();
var tmpFunc = myObj.myFunc;
// this = window
tmpFunc();
Another issues is closures, where variables and properties available to nested functions are dependent on the outer functions. Combined with the floating "this", leads to highly dynamic behaviour which can only be assessed at runtime. |
|