Altogether, rather neglected JavaScript functions
Terry's pointing to David Kellogg's post on JavaScript's watch() (coupled with some prompting from Jason) inspired me to add call and apply. At this point, both of these functions have made it into integral pieces of code, both for my own projects and for the book. Calling things like the following makes it infinitely easier to write OO JavaScript:
window.addEventListener('load', new Function("Throbber.prototype.attach.apply(throbber, arguments);"), false);
This needs to happen, rather than...
window.addEventListener('load', throbber.attach, false);
...as JavaScript's this can work in strange, mysterious ways to those uninitiated to prototype-based languages. In the first code block, this would return a reference to the throbber instance of the Throbber class. The the second code block, this would return a reference to the window object.
Edited (12/19/06): I just found that Bret Taylor wrote about this in July. How did I not find his site until now?
Labels: javascript

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home