开发者

Does Mootools prevents javascript closure 100%?

开发者 https://www.devze.com 2022-12-27 19:42 出处:网络
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 ja

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消