关于this
this
应该是Javascript里永恒的面试题。这次只说说硬绑定里的陷阱题。
硬绑定
求下面这个题目的输出:123456789101112131415161718function foo(cb) { cb();}var a = { a: "a in a", getA:function(){ console.log(this.a);}};var b = { a: "a in b"};var getA = a.getA;var getA2 = getA.bind(a);a.getA();//"a in a"getA();//afoo(a.getA);//agetA2.call(b);//"a in a"