New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
闭包那一章有疑惑,望解答 #14
Comments
朋友,感觉是你错误的理解 「当函数以函数调用时」 的意思,这句话的意思是:当一个在全局作用域中定义的函数被调用时。如以下代码所示: function func1() {
return this;
}
var obj = {};
obj.func2 = function() {
return this;
};
console.log(func1() === window;) // 当函数以函数调用
console.log(obj.func2() === obj;) // 当函数以对象的方法调用 所以在全局作用域中调用函数 至于你对构造函数中的 |
function func1() {
function func2() {
console.log(this)
}
} 首先,你给出的这个代码片段没有执行语句,并不能判断 function func1() {
function func2() {
console.log(this)
}
return func2;
}
func1()(); // window 因为这样会让人觉得,是
如果想让 function func1() {}
func1.func2 = function() {
console.log(this)
}
func1.func2(); // func1(){} |
@stone0090 谢谢您,我重新理了一遍思路 现在理解了 |
懂了!谢谢大湿胸 |
好牛啊 |
javascript-lessons/2.4-Scope&Closure/README.md
您好,今天刚好重新看了javascript权威指南,根据此书8.2章中的解释
而您所说指向调用函数的那个对象,函数也是一个对象,当在一个函数中调用另一个函数时,this仍然指向的是全局对象,您看是否有歧义
BTW,能否提个建议把构造函数中的this做下解释,这段我也看了好久才看懂...
The text was updated successfully, but these errors were encountered: