var o = {
of : function () {
console.log(this);
var printThis = function () {
console.log(this);
}
printThis();
}
};
o.of();
Object {}
Window {external: Object, chrome: Object, document: document, o: Object, speechSynthesis: SpeechSynthesis…}
var printThis = function () {
console.log(this);
}
var o = {
of : function () {
console.log(this);
printThis();
}
};
o.of();
Object {}
Window {external: Object, chrome: Object, document: document, o: Object, speechSynthesis: SpeechSynthesis…}
结论
- 函数不管在哪里(顶部作用域还是局部作用域)调用,都作为全局对象的属性进行调用。
- 作为对象的属性,函数则称为方法
- 方法内部的this指针指向其调用对象