View Single Post
Old 09-01-2010, 09:33 AM   PM User | #18
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,880
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
you’re misunderstanding closures. a closure not only has access to its inner and outer variables, it also preserves them over the usual lifetime. (basically having acces to variables that would normally have been destroyed)

PHP Code:
Function.prototype.bind = function (obj) {
    var 
fn this;
    return function () {
        return 
fn.apply(objarguments);
    }
}; 
without the closure, the variable fn would be destroyed after calling (local variables exist only while the function is called). due to the closure, JS "remembers" (keeps in memory) the value of fn (in this case a reference to a said function object)

Quote:
Originally Posted by DaveyErwin View Post
It returns an Object , don't forget my thanks....uh
lol
__________________
please post your code wrapped in [CODE] [/CODE] tags

Last edited by Dormilich; 09-01-2010 at 09:40 AM..
Dormilich is offline   Reply With Quote