search

Home  >  Q&A  >  body text

js作用域的问题?

var len = 5;var fn1 = function  () {    console.log(this.len);
};var main = {
    method: function (fn) {
        fn();        arguments[0]();
    },
    len : 10};
main.method(fn1);


素颜素颜2920 days ago853

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:27:46

    JS scope problem? -PHP Chinese website Q&A-JS scope problem? -PHP Chinese website Q&A

    Let’s take a look and learn.

    reply
    0
  • 迷茫

    迷茫2017-02-22 09:22:25

    var fn1 = function  () {   
         console.log(this.len);
    };

    直接执行fn1的结果是5 很显然这个函数里面的this指向的是window

    reply
    1
  • Cancelreply