473,655 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simply super

Hello list. This is my first message and it's nothing needful but
rather playful. I'd just like to hear some thoughts on something I
consider to be a curiosity of javascript usage. I've seen a lot of
folks looking to implement some kind of super-like functionality in
javascript and it's usually baked into some larger effort of emulating
classes. However if you really need* that type of functionality why
not get it like so:

//assuming that foo has its own sayIt property and a sayIt property in
its prototype chain
var backup = foo.sayIt;
delete foo.sayIt;
foo.sayIt(); // now, delegates up the chain
foo.sayIt = backup;

So you can see that it's easy enough to make use of javascript's built-
in property delegation/lookup to emulate super-like functionality. And
if you wanted to make easier use of that pattern:

foo.supe = function( prop ){
var backup = this[prop];
delete this[prop];
if( typeof this[prop] == 'function' ){
var r = this[prop]();
}else{
var r = this[prop];
}
this[prop] = backup;
return r;
};

foo.supe('sayIt ');

So there's an example of a general purpose super-like function. It
doesn't include argument passing even though that's entirely possible.
So is that not the simplest way of getting super-like functionality?
If anyone has some feedback I'd love to hear it. I hope I've been
clear.

You can also see a more complete working example of the code at:
http://highlight.tumblr.com/post/55510055/

* I haven't personally needed super-like functionality in my
javascript coding. Apparently, neither has Crockdolf as you can now
read at the bottom of his scroll of classical javascript teachings:
"I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake."
from: http://javascript.crockford.com/inheritance.html

--
thanks for reading,
m

Oct 29 '08 #1
25 1772
On Oct 29, 2:58*pm, "dylan m. austin" <mr.f...@gmail. comwrote:
Hello list. This is my first message and it's nothing needful but
rather playful. I'd just like to hear some thoughts on something I
consider to be a curiosity of javascript usage. I've seen a lot of
folks looking to implement some kind of super-like functionality in
javascript and it's usually baked into some larger effort of emulating
classes. However if you really need* that type of functionality why
not get it like so:
The larger effort is largely a misguided attempt to make JavaScript
work like Java (or other languages with classical inheritance
patterns.)
>
//assuming that foo has its own sayIt property and a sayIt property in
its prototype chain
var backup = foo.sayIt;
delete foo.sayIt;
foo.sayIt(); // now, delegates up the chain
foo.sayIt = backup;
Yikes.

https://developer.mozilla.org/En/Cor.../Function/Call
>
So you can see that it's easy enough to make use of javascript's built-
in property delegation/lookup to emulate super-like functionality. And
if you wanted to make easier use of that pattern:

foo.supe = function( prop ){
* var backup = this[prop];
* delete this[prop];
* if( typeof this[prop] == 'function' ){
* * var r = this[prop]();
* }else{
* * var r = this[prop];
* }
* this[prop] = backup;
* return r;

};

foo.supe('sayIt ');

So there's an example of a general purpose super-like function. It
doesn't include argument passing even though that's entirely possible.
Of course.
So is that not the simplest way of getting super-like functionality?
If anyone has some feedback I'd love to hear it. I hope I've been
clear.
It is easy enough to invoke a method of the "super" object. What is
trickier is doing it without mentioning the object by name.
>
You can also see a more complete working example of the code at:http://highlight.tumblr.com/post/55510055/

* I haven't personally needed super-like functionality in my
javascript coding. Apparently, neither has Crockdolf as you can now
read at the bottom of his scroll of classical javascript teachings:
"I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake."
from:http://javascript.crockford.com/inheritance.html
Too bad the Prototype crowd hasn't read this. Would you post a link
at the bottom of one of their blogs?
Oct 30 '08 #2
Yikes.
>
https://developer.mozilla.org/En/Cor...ference/Global...
Sure, good ol' call. I'm glad you mention it but to use it you've got
to find your own way reference the function you want to call. As you
also wrote:
It is easy enough to invoke a method of the "super" object. *What is
trickier is doing it without mentioning the object by name.
So that's exactly what temporary removal of the local property
achieves, you don't have to reference the 'super' object.
Too bad the Prototype crowd hasn't read this. Would you post a link
at the bottom of one of their blogs?
The quote from Crockford's page? I can't be sure they haven't read it
and besides I'm not familiar with the crowd or their blogs.
Oct 30 '08 #3
On Oct 30, 1:11*pm, "dylan m. austin" <mr.f...@gmail. comwrote:
Yikes.
https://developer.mozilla.org/En/Cor...ference/Global...

Sure, good ol' call. I'm glad you mention it but to use it you've got
to find your own way reference the function you want to call. As you

also wrote:
It is easy enough to invoke a method of the "super" object. *What is
trickier is doing it without mentioning the object by name.

So that's exactly what temporary removal of the local property
achieves, you don't have to reference the 'super' object.
In a very clumsy way. I wouldn't recommend that method.
Oct 30 '08 #4
On Oct 30, 8:10*pm, David Mark <dmark.cins...@ gmail.comwrote:
>
In a very clumsy way. *
Crockford does mention exactly this in one of his videos, when while
explaining the prototype chain somebody asks "What happens if a
property is deleted from an instance ?"

<http://developer.yahoo .com/yui/theater/>

I wouldn't recommend that method.
Which would you recommend ?

--
Jorge.
Oct 30 '08 #5
On Oct 30, 3:46*pm, Jorge <jo...@jorgecha morro.comwrote:
On Oct 30, 8:10*pm, David Mark <dmark.cins...@ gmail.comwrote:
In a very clumsy way. *

Crockford does mention exactly this in one of his videos, when while
explaining the prototype chain somebody asks "What happens if a
property is deleted from an instance ?"

<http://developer.yahoo .com/yui/theater/>
I wouldn't recommend that method.

Which would you recommend ?
I agree with the Crockford quote. Trying to implement classical
inheritance patterns with an ECMAScript-based language is a waste of
time.
Oct 30 '08 #6
Jorge meinte:
On Oct 30, 8:10 pm, David Mark <dmark.cins...@ gmail.comwrote:
>In a very clumsy way.

Crockford does mention exactly this in one of his videos, when while
explaining the prototype chain somebody asks "What happens if a
property is deleted from an instance ?"
But does he endorse it?

Gregor
Oct 30 '08 #7
On Oct 29, 11:58 am, "dylan m. austin" <mr.f...@gmail. comwrote:
* I haven't personally needed super-like functionality in my
javascript coding. Apparently, neither has Crockdolf as you can now
read at the bottom of his scroll of classical javascript teachings:
"I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake."
from:http://javascript.crockford.com/inheritance.html
I don't see how the prototypal-based or class-based systems have
anything to do with needing super-like functionality. These are
unrelated issues.

Peter
Oct 31 '08 #8
On Oct 29, 5:30 pm, David Mark <dmark.cins...@ gmail.comwrote:
The larger effort is largely a misguided attempt to make JavaScript
work like Java (or other languages with classical inheritance
patterns.)
I disagree. Classes are a pattern. Prototypes are a pattern. Each is
useful in different situations. It just so happens that JavaScript has
some in-language support for the prototype style. JavaScript is very
capable of expressing the class style because JavaScript functions are
lambdas (more or less.) "Structure and Interpretation of Computer
Programs" has many elegant uses of the class style in Scheme and
Scheme doesn't have any particular language support for any OOP
programming style. Lambdas are all it takes. To throw away the option
of using the class style where it is appropriate just because
JavaScript doesn't have bits os syntax sugar for it would be a shame.

It looks like the next major revision of ECMAScript will have some
sort of class construct in it. The interesting thing about how the
committee seems to be designing it is that these classes are just
sugar for the prototype-based system.

Peter
Oct 31 '08 #9
On 30 oct, 16:16, Gregor Kofler <use...@gregork ofler.atwrote:
Crockford does mention exactly this in one of his videos, when while
explaining the prototype chain somebody asks "What happens if a
property is deleted from an instance ?"

But does he endorse it?

Gregor
It's not likely. Did you see the excerpt from his writing included at
the bottom of the first message in this thread?
Oct 31 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1670
by: Clarence Gardner | last post by:
The super object is considered a solution to the "diamond problem". However, it generally requires that the ultimate base class know that it is last in the method resolution order, and hence it should not itself use super (as well as supplying the ultimate implementation of an overridden method.) However, a problem comes up if that ultimate base class is also the base class for another which inherits from it and another independent base...
11
5026
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in function on pages 89-90. Based on the example on page 90, I wrote this test code : class A(object): def test(self): print 'A'
0
1233
by: Michele Simionato | last post by:
Here is an idea for a nicer syntax in cooperative method calls, which is not based on Guido's "autosuper" example. This is just a hack, waiting for a nicer "super" built-in ... Here is example of usage: from cooperative import Cooperative class B(Cooperative): def print_(self):
0
1503
by: Delaney, Timothy C (Timothy) | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195 This is a new version of super that automatically determines which method needs to be called based on the existing stack frames. It's much nicer for writing cooperative classes. It does have more overhead, but at this stage I'm not so concerned about that - the important thing is it actually works. Note that this uses sys._getframe() magic ...
6
2004
by: Steven Bethard | last post by:
When would you call super with only one argument? The only examples I can find of doing this are in the test suite for super. Playing around with it: py> class A(object): .... x = 'a' .... py> class B(A): .... x = 'b' ....
7
5246
by: Kent Johnson | last post by:
Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? The super() method only works correctly in multiple inheritance when the base classes are written to expect it, so "Always use super()" seems like bad advice. OTOH sometimes you need super() to get correct behaviour. ISTM "Only use super() when you know you need it" might be
7
1924
by: Pupeno | last post by:
Hello, I have a class called MyConfig, it is based on Python's ConfigParser.ConfigParser. It implements add_section(self, section), which is also implemented on ConfigParser.ConfigParser, which I want to call. So, reducing the problem to the bare minimum, the class (with a useless add_section that shows the problem): .... def add_section(self, section): .... super(MyConfig, self).add_section(section)
9
2195
by: Mike Krell | last post by:
I'm reading Alex Martelli's "Nutshell" second edition. In the section called "Cooperative superclass method calling", he presents a diamond inheritance hierachy: class A(object): def met(self): print "A.met" class B(A): def met(self): print "B.met"
4
1716
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.