simply super

D

dylan m. austin

Here's a couple of blog posts.  I'm surprised that no-one have mentioned
John Resig's yet.

Why?  Comic relief?

[snip]

Hehe, I don't know why I get a kick of out of the resig-bashing. It's
probably not the best of behavior.

I too haven't been following the latest work on the ECMAScript
specifications but here's one entry I found interesting on Johh's
blog:
http://ejohn.org/blog/objectgetprototypeof/

It covers the Object.getPrototypeOf method they've come up with for
ECMAScript 3.1 and shows a basic example of getting super-
functionality with it. I'll reproduce that here:
function Person(){}

Person.prototype.kick = function(type){
alert(type + " kick!");
}

function Norris(){}

// Inherit properties from Person
Norris.prototype = new Person();

Norris.prototype.kick = function(){
Object.getPrototypeOf(this).kick("Roundhouse");
};

His example isn't dependent on correct binding of the 'super' call.
For a more real-world use it would probably need the use of 'call',
like so:

Norris.prototype.kick = function(){
Object.getPrototypeOf(this).kick.call(this,"Roundhouse");
};

So how about that, David? You can use call and avoid constructor
reference clumsiness. Pretty super or what? If you are coding for 3.1
and up implementations, anyway.
 
D

David Mark

Why?  Comic relief?

Hehe, I don't know why I get a kick of out of the resig-bashing. It's
probably not the best of behavior.

It is his lousy scripts, blog entries, books, etc. that get the well-
deserved criticism here. As for him as a person, he is an idiot, but
that is OT.
I too haven't been following the latest work on the ECMAScript
specifications but here's one entry I found interesting on Johh's
blog:http://ejohn.org/blog/objectgetprototypeof/

I just can't see wasting five minutes of my life to read more of his
nonsense.
 
T

Thomas 'PointedEars' Lahn

dylan said:
[...]
http://ejohn.org/blog/objectgetprototypeof/

It covers the Object.getPrototypeOf method they've come up with
for ECMAScript 3.1 and shows a basic example of getting super-
functionality with it. I'll reproduce that here:
function Person(){}

Person.prototype.kick = function(type){
alert(type + " kick!");
}

function Norris(){}

// Inherit properties from Person
Norris.prototype = new Person();

Obviously, as it has been explained numerous times before, that is _not_ the
proper way to emulate class-based inheritance in a prototype-based
programming language (inheriting from an instance created with a constructor
instead of from the prototype object of that constructor), and so ...
Norris.prototype.kick = function(){
Object.getPrototypeOf(this).kick("Roundhouse");
};

.... I seriously hope that Resig doesn't have a word to say in creating the
next revision of the ECMAScript Specification if the proposed feature is
merely based on this or his other misconceptions.

This example does not make sense, for you can simply omit the definition of
Norris.prototype.kick and the prototype chain would work its way.

Getting the next object in the the prototype chain from a prototype method
is only useful if duplication of code should be prevented. However,
devising a method for that is merely syntactic sugar as the identifier of
the constructor of the prototype is known. Such a feature should then be
inherited from Object.prototype, and not `Object', by a property that has
the DontEnum attribute:

this.super.kick("Roundhouse");

or as a superglobal

super.kick("Roundhouse");

In my libraries, I have the method that sets up the prototype chain add a
`_super' property to the prototype object that refers to the next object in
the prototype chain. (One has to take care, though, that an iterator method
filters it out for for-in iteration.)

`super' is a future reserved word in ECMAScript Ed. 3; it does not make
sense to invent another mechanism instead of defining `super' (including a
more expensive method call) in later revisions of ECMAScript.


PointedEars
 
P

Peter Michaux

On Nov 2, 2:38 am, Thomas 'PointedEars' Lahn <[email protected]>
wrote:

[snip]
... I seriously hope that Resig doesn't have a word to say in creating the
next revision of the ECMAScript Specification if the proposed feature is
merely based on this or his other misconceptions.

He doesn't participate much on the es-3.1 or es-harmony email lists
and does not appear to be on the formal committee.

[snip]

Peter
 
D

dylan m. austin

dylan said:
It covers the Object.getPrototypeOf method they've come up with
for ECMAScript 3.1 and shows a basic example of getting super-
functionality with it. I'll reproduce that here:
function Person(){}
Person.prototype.kick = function(type){
  alert(type + " kick!");
}
function Norris(){}
// Inherit properties from Person
Norris.prototype = new Person();

Obviously, as it has been explained numerous times before, that is _not_ the
proper way to emulate class-based inheritance in a prototype-based
programming language (inheriting from an instance created with a constructor
instead of from the prototype object of that constructor), and so ...

I'm glad you mention that. It's a shame the most propagated example of
inheritance in javascript is exactly that.
... I seriously hope that Resig doesn't have a word to say in creating the
next revision of the ECMAScript Specification if the proposed feature is
merely based on this or his other misconceptions.

This example does not make sense, for you can simply omit the definition of
Norris.prototype.kick and the prototype chain would work its way.

I'm pretty sure homeboy wrote that as an example where you were
supposed to 'fill in the blanks' a bit, as if there were some extra
functionality added in the Norris.prototype.kick method. Though
undoubtedly he should have taken the time to create a more lucid
example.
Getting the next object in the the prototype chain from a prototype method
is only useful if duplication of code should be prevented.  However,
devising a method for that is merely syntactic sugar as the identifier of
the constructor of the prototype is known.  Such a feature should then be
inherited from Object.prototype, and not `Object', by a property that has
the DontEnum attribute:

  this.super.kick("Roundhouse");

or as a superglobal

  super.kick("Roundhouse");

In my libraries, I have the method that sets up the prototype chain add a
`_super' property to the prototype object that refers to the next object in
the prototype chain.

The only thing I meant to point out by mentioning Resig's post was
that there is now a proposed feature in 3.1 that allows direct access
to an object's [[prototype]]. Thus you wouldn't need to be adding your
own _super property to your prototypes. Not to say I prefer the
proposed feature or anything.

Also in future posts all try and avoid mentioning the names of any
pundits as it only creates noise here.
 
T

Thomas 'PointedEars' Lahn

Peter said:
He doesn't participate much on the es-3.1 or es-harmony email lists
and does not appear to be on the formal committee.

Thanks, that's comforting ;-)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top