Finally bothered to figure out what call() does, precisely, and why it needs 'this' passed in as an "extra" parameter.

Great explanation here, in

var x = 10;
var o = { x: 15 };
function f(message)

f("invoking f");, "invoking f via call");

So the deal is that "this" becomes the "new" "this" within the function, making it approximate a real object oriented overload. So if you're, say, extending some ExtJS objects in ExtJS 2, this is how you'd call the superclass' functions from the class' extension.

So in Sencha's tutorial, you're first, very smartly, making a trivial extension of an existing object with code like this...

    initComponent:function() {
// call parent initComponent;
} // end of function initComponent

So initComponent will do the same that it's always done, but will pull in the extended (though, for now, only trivially extended with no new functionality) object's methods, props, etc. when "this" is called.

The whole Javascript revolution still seems like a giant kludge, but that obviously doesn't make it evil. It's a good hack, but takes a little head rethreading.

Labels: , ,