Apr 12
$.fn.delayHide(time, callbackArgument) { var self = this; setTimeout(function() { callbackArgument.call(self); }, time); }
I find that I have to use the var self = this;
pattern far too often in JavaScript.
The darn magic scoping of this really gets ya.
I also had someone ask me why foo never ended up containing something:
var foo = bar(function() { .... return something; });
It made me more worried about adding closures to Java :)
April 13th, 2007 at 7:16 am
Not all closures proposals are equal. In this example:
public void process() {
foo = bar( { =>
….
return something;
});
}
The return will return from process() in BGGA closures as you hint at, and foo will not be set.
But in FCM closures – http://docs.google.com/Doc?id=ddhp95vd_0f7mcns – the return will return back to the invoker of the closure, as with inner classes, and foo will be set.
Which semantic do you prefer?
April 15th, 2007 at 1:46 pm
crockford calls it a ‘design error’ i think. i mean technically an inner anonymous function _is_ a new object, so it should get a new ‘this’, no? id definitely like it to inherit via lexical scoping as well, but what can you do.
are they fixing this bug in 2.0?
May 19th, 2008 at 12:00 am
thanks for posting this.
June 24th, 2008 at 2:00 am
thanks!