var test ={
'a':1,
'b':{
'b1':function(){
console.log(this === test);
}.bind(test)
}
}
test.b.b1();
为什么结果为false……
var test ={
'a':1,
'b':{
'b1':function(){
console.log(this === test);
}.bind(test)
}
}
test.b.b1();
为什么结果为false……
var test = {
'a': 1,
c: (function () {
console.log(test)
})(),
'b': {},
}
test.b.b1 = function() {
console.log(this == test);
}.bind(test)
test.b.b1();
输出结果
undefined
true
var test ={
'a':1,
'b':{
'b1':function(){
console.log(test);
console.log('--------------------\r\n');
console.log(this);
console.log('--------------------\r\n');
}.bind(null)
}
}
test.b.b1();
结果是一样的
var test ={
'a':1,
'b':{
'b1':function(){
console.log(test);
console.log('--------------------\r\n');
console.log(this);
console.log('--------------------\r\n');
}.bind(test)
}
}
test.b.b1();
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
bind时test值为undefined,因此
this === test
中的this指向了window
,所以为false