var name = 'the window';
var obj = {
name: 'the obj',
func: function () {
this.name = 'foo';
}.bind(window)
}
var bar = new obj.func();
console.log(bar.name)
第一步,打开浏览器,
第二步,按F12,打开console,
第三步,输入以上代码
var a = {
b: function() {
var func = function() {
console.log(this.c);
};
func();
}.bind(this),
c: 'hello'
}
var c = 'ccccc'
a.b();
var a = {
b: function() {
var func = function() {
console.log(this.c);
}.bind(this);
func();
},
c: 'hello'
}
var c = 'ccccc'
a.b();