var len = 5;var fn1 = function () { console.log(this.len); };var main = { method: function (fn) { fn(); arguments[0](); }, len : 10}; main.method(fn1);
越努力越幸运!!!
JS scope problem? -PHP Chinese website Q&A-JS scope problem? -PHP Chinese website Q&A
Let’s take a look and learn.
var fn1 = function () { console.log(this.len); };
直接执行fn1的结果是5 很显然这个函数里面的this指向的是window
JS scope problem? -PHP Chinese website Q&A-JS scope problem? -PHP Chinese website Q&A
Let’s take a look and learn.
直接执行fn1的结果是5 很显然这个函数里面的this指向的是window