super.apply(this, arguments)
Garrett Smith
dhtmlkitchen at gmail.com
Thu Dec 20 19:49:24 PST 2007
On Dec 20, 2007 11:29 AM, P T Withington <ptw at pobox.com> wrote:
> Given that we already have a whacky syntax for calling the super
> initializer (which I confess I had forgotten), why not allow apply
> there? It's unambiguous there, since you are only allowed to call the
> super initializer. This syntax is just letting you override how your
> arguments are passed on to your super initializer. What is the
> default if I don't specify a call to my super initializer? Does it
> get all my arguments, or none of them?
>
> class A extends B {
> function A(x,y,z) : super.apply (this, arguments) { ... }
> }
>
> ?
>
> Personally, I really don't like the magic of the class name naming the
> initializer. I would rather see a magic method name, say
> `initialize`, so you say:
>
> class A extends B {
> function initialize(x,y,z) {
> super.initialize.apply(this, arguments);
> ...
> }
> }
>
> but that is probably too radical. On the plus side, you don't have to
> repeat the class name, which makes easier maintenance and code reuse,
> on the minus side there is a magic method name and you have to decide
> whether to enforce arglist congruency or not (an issue hidden by
> having each initializer have the class name as its name).
>
So you're proposing making some sort of "instance constructor"
property on the class
MyClass.instanceConstructor.newApply(lockable, args );
Would you be able to call that with another object?
function LockableFile() {
var lockable = Lockable.createInstance();
var lockableFile = FIle.instanceConstructor.newApply(lockable, args);
}
What about calling a nested class?
class Menu() {
class Item() {
}
function buildSingleItemMenu(...args) {
this.new Item(...args);
}
function buildSingleItemMenu( ) {
return new Menu().Item.instanceConstructor.newApply( arguments );
}
Just some ideas.
>
> On 2007-12-20, at 13:05 EST, Jeff Dyer wrote:
>
> > Sorry, I didn't mean to sound so flippant.
> >
> > As you may know, super expressions limit the binding of the name
> > after the
> > dot to the base class bindings. So the fragment above would call the
> > super
> > instance method 'apply', not the super constructor.
Right, because the super is a Function, which gets an apply method
from Function.prototype.
We could give
> > 'apply'
> > some special meaning when the first argument is 'this', but the super
> > constructor will have already been called during initialization.
> >
> > None of this means that the desired semantics wouldn't be possible to
> > achieve with another syntax. My guess is that it would be somehow
> > similar to
> > the current super initializer syntax, which looks like this:
> >
> > class A extends B {
> > function A(x,y,z) : super (x,y,z) { }
> > }
> >
> > Suggestion welcomed.
> >
I kind of like the syntax P T Withington suggests for reasons he
mentioned but I don't like the name | initialize | to refer to the
instance constructor.
Garrett
> > Jd
> >
> > On 12/20/07 9:04 AM, Dean Edwards wrote:
> >
> >>> On 12/20/07 7:20 AM, P T Withington wrote:
> >>>
> >>>> Ok. I didn't look in the wiki to start with because of that,
> >>>> hence I
> >>>> ask on the list: can I apply my super's constructor as in the
> >>>> subject
> >>>> line?
> >>>>
> >> Jeff Dyer wrote:
> >>> Sorry, but you can't.
> >>>
> >>
> >> That's a shame.
> >>
> >> -dean
> >
>
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>
--
Monkey, so they say, is the root of all people today.
More information about the Es4-discuss
mailing list