Re: JavaScript closures article



Manish Tomar wrote:
Hi,

Please check this small article on my experience on closures in
JavaScript.
http://manishtomar.blogspot.com/2007/04/javascripts-power-of-closure.html
It gives a simple explanation of closures. Do post any comments if you
like it.

Um, personally, I found this article poorly-worded, not well written and *very* unprofessional. I doubt many will take this article seriously.

Not to mention your code clutters the global namespace (the Window object). And I could be wrong, but I see a memory leak in the making. Not by the circular reference, but by nesting closures. (See MDC link below.) Also, I am quite certain that function (createFuncs) could be written more simply and possibly more efficiently. See:

http://developer.mozilla.org/en/docs/A_re-introduction_to_JavaScript#Closures

I will continue to use these professionally written documents on closures (and memory leakage):

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions#Nested_functions_and_closures
http://developer.mozilla.org/en/docs/A_re-introduction_to_JavaScript#Memory_leaks
http://jibbering.com/faq/faq_notes/closures.html
http://www.codeproject.com/jscript/LeakPatterns.asp

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am kidding. No I am not.
.



Relevant Pages

  • Re: speed issues traversing the DOM.
    ... The "what" argument is unnecessary and foreshadows a bigger problem. ... I definitively understand nothing about closures. ... circular reference = no memory leak. ... Open your task manager and find out. ...
    (comp.lang.javascript)
  • Re: Adding events in a loop with arguments
    ... but creates an additional execution object on the scope chain ... Other methods that don't have memory leak problems are: ... Use the built-in Function object as a constructor: ... I'll look into closures and of course ...
    (comp.lang.javascript)
  • Re: Adding events in a loop with arguments
    ... I am attaching the code for a ... but creates an additional execution object on the scope chain ... Other methods that don't have memory leak problems are: ... I'll look into closures and of course ...
    (comp.lang.javascript)
  • Re: Some language proposals.
    ... >> Could somebody point me to an explanation of why closures are broken ... > def b: ... Methinks you forgot to return something somewhere. ... But what happens in other languages which support closures, ...
    (comp.lang.python)
  • Re: A question (confusion) about closure
    ... Robert Wilensky's explanation of closures tweaks one's intuitive ... understanding of the topic. ...
    (comp.lang.lisp)