首先看一道网易的面试题: var a = { a:"haha", getA:function(){ console.log(this.a); } } var b = { a:"hello" } var getA = a.getA; var getA2 = getA.bind(a); function run(fn){ fn(); } //分别输出 a.getA();//haha getA();//window下面的a对象 run(a.getA);//window下面…
背景: 小明想要用数组的形式为 Cls.func 传入多个参数,他想到了以下的写法: var a = new Cls.func.apply(null, [1, 2, 3]); 然而浏览器却报错Cls.func.apply is not a constructor. 乍一看是 new 操作符去修饰 Cls.func.apply 了,于是他又这么写: var a = (new Cls.func).apply(null, [1, 2, 3]); 浏览器依旧报错...好吧,还是好好查一查相关的解决方法吧…