sproutcore / sproutcore

JavaScript Application Framework - JS library only
sproutcore.com
Other
2.15k stars 291 forks source link

'superclass' behaves differently in class and instance #518

Closed bronson closed 10 years ago

bronson commented 13 years ago

The superclass property/method is inconsistent: in a class it's a property that contains the superclass, in an instance it's a method that calls the superclass's method of the same name.

One = SC.Object.extend({one: 1});
a_one = One.create();

One.superclass        # returns SC.Object, One's superclass
a_one.superclass()    # inside a method, calls that method on the superclass.

This seems unnecessarily confusing.

Apologies if I got anything wrong, I'm just trying to understand http://docs.sproutcore.com/?#doc=SC.Object&method=superclass&src=false

publickeating commented 11 years ago

I've always used sc_super(), so I'm not really sure about this method. Since Safari 2, the apparent browser that can't use this, is essentially non-existent anymore, maybe we can start using this function instead of sc_super. If that is the case, I would want to rename it.

dcporter commented 11 years ago

@mauritslamers and I have been discussing related behavior. Apparently ES5 or something no longer supports arguments.callee in strict mode, which could be a consideration in the future. Also I've never been a fan of the string replacement that sc_super entails. It's a weird requirement for the build tools.

The trouble is that without arguments.callee, there is no way for the function to endogenously access itself, right? How does the superclass method accomplish this?

Anyway, assuming that's the case, then the developer will have to refer to it by name on the superclass... which is potentially fragile and mildly annoying, but is it a big deal? Please discuss amongst yourselves.

At any rate, agreed that the behavior of superclass should be consistentified.

dcporter commented 10 years ago

Alright the whole point of SC.Object#superclass was to allow use of SC without the build tools, which I think is an old, broken dream. Not only that, but it appears that superclass is inferior to sc_super(); in that it requires the developer to know and pass the arguments individually. I'm going to deprecate the instance method for 1.11.