How about this.$super()?
--
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/
>
> var Thingy = Class.create({
> nifty: function nifty(foo, bar) {
> nifty.$super.call(this, foo);
> }
> });
>
> It just ignores the function name and complains that 'nifty' is not
> defined. This works:
Wouldn't you have to do this to preserve scope?
this.nifty.$super.call( this );
Myself, I've never liked the .call syntax much because I mistake it with
apply: the two words seem arbitrary. But, yeah, I can see that pre-binding
every overridden method of every object would be a big overhead.
Perhaps I would do:
var B = Class.create(A, {
nifty: function(){
var $super = this.nifty.$super.bind( this );
// $super refers to A.nifty() bound to this
$super();
}
});
[1] Please correct if this is wrong!
How about simplifying further:
var B = Class.create( A,
function nifty(){
nifty.$super.call(this);
}
, function alsoNifty(){
this.nifty();
}
);
Ie, Class.create takes any number of objects of functions or functions. If
functions, the function name is used.
I suppose if you wanted both you could say named functions get added to the
class as a method, whereas the object result of executing anon functions get
added.
Over complicated?
Hi Robert,
Um, "this.callSuper(arguments, arg)" (or "this.callSuper(nifty, arg)")
> > arguments.callee.$super.call(this, arg);
> > this.callSuper(arguments, arg);
>
> "six of one, half-dozen of the other"...
is precisely *one* argument more than Resig's "this._super(arg)", but
without the cost of the closures and unnecessary, misleading (IMV)
magic. It's a lot clearer than the raw syntax needed with anonymous
functions. "Six of one, half-dozen of the other" seems a bit harsh.
> Honestly, at this point I'm mostly worried that that we may get> usability...
> enamored with a solution that is different, but not necessarily all
> that much "better". More performant, yes, but at the cost of
That's interesting. I started down this road precisely because I
found the existing API flawed;
I didn't realize you'd done a "crappy performance in supercalls"
thrread (I was away from this group for a while). I'd seen the
excellent work you did with curried and bound functions, though, and
I'm glad to hear that will be finding its way into 1.6.1.
I have a hunch we could get function names in the same way that we implement
Function#argumentNames. A regex on the toString.
> > I see where you're coming from, but FWIW I'm with Allen on this one.
> > Also, there's no standard way to get the name of a function until
> > ECMAScript5 (which standardizes the truly outrageous idea that
> > function instances should have -- gasp! -- a "name" property), and at
> > the moment although Firefox 3.5, Chrome 2, and Safari 4 all already
> > have that property, IE7 (at least, haven't tested IE8) and Opera10 do
> > not.
>
> I have a hunch we could get function names in the same way that we
> implement Function#argumentNames. A regex on the toString.
I should have looked first - this is function decompilation and considered a
bad thing.