window外不是还有一层。 all JavaScript functions are closures
这个问题的核心就是,如果外层函数不返回任何值,内层函数还算不算是闭包?答案貌似是算闭包。以下摘自Mozilla(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures)Consider the following:function init() { var name = "Mozilla"; // name is a local variable created by init function displayName() { // displayName() is the inner function, a closure alert (name); // displayName() uses variable declared in the parent function } displayName(); } init();init() creates a local variable name and then a function called displayName(). displayName() is the inner function (a closure) — it is defined inside init(), and only available within the body of that function .
看不看的懂英文 all JavaScript functions are closures;看不看的懂我的注释 window外不是还有一层。看不看的懂我的回答 你基本上对象都没选上。
看不看的懂英文 all JavaScript functions are closures; -------------------------------------- 看不懂啊,all是啥意思?看不看的懂我的注释 window外不是还有一层。 -------------------------------------- 看不懂啊,原来这句是注释看不看的懂我的回答 你基本上对象都没选上。 -------------------------------------- 看不懂啊,从闭包能扯到对象太强了
not object is target should rely on contextual
What a F***ing hard discussion! But it seems you are the only one who gives the right answer at #2. Anyway, take the score and thank you.
闭包比较关键的地方在于函数A执行完毕后,函数里的变量或参数并没有被回收而被其他函数B(常见的情况就是B在A内声明或定义)引用着。你的例子,
第一个:generateClosure执行完后,它返回的函数(也就是counter)还引用着它的变量count,所以是闭包。
第二个:generateClosure执行完后,它没有返回函数,它的外面也没有其他函数引用着它的变量,它的变量被回收,所以不是闭包。
但是上面的方法返回的是get返回的值,因为返回的不是函数,就没有闭包的概念了。
all JavaScript functions are closures
var name = "Mozilla"; // name is a local variable created by init
function displayName() { // displayName() is the inner function, a closure
alert (name); // displayName() uses variable declared in the parent function
}
displayName();
}
init();init() creates a local variable name and then a function called displayName(). displayName() is the inner function (a closure) — it is defined inside init(), and only available within the body of that function .
all JavaScript functions are closures;看不看的懂我的注释
window外不是还有一层。看不看的懂我的回答
你基本上对象都没选上。
看不看的懂英文
all JavaScript functions are closures;
--------------------------------------
看不懂啊,all是啥意思?看不看的懂我的注释
window外不是还有一层。
--------------------------------------
看不懂啊,原来这句是注释看不看的懂我的回答
你基本上对象都没选上。
--------------------------------------
看不懂啊,从闭包能扯到对象太强了
is target
should rely on contextual
What a F***ing hard discussion! But it seems you are the only one who gives the right answer at #2. Anyway, take the score and thank you.