While I was talking about javascript closure to my friend, I was told that using Mootools can prevent closures 100%. To my knowledege, a variable causes a closure. How does Mootools itself prevents javascript closure? I think my friend is saying that M开发者_开发知识库ootools' functions are closure-safe functions.
Any suggestions?
A variable does not cause a closure. A closure is created by a function A that returns another function B referring to one of A's local variables. For example, the expression
(function() { var x; return { get: function () { return x; }, set: function (y) { return x=y; } }; })();
returns an object containing two functions referring to the local variable x
. We say that get
and set
"close over" x
.
精彩评论