What is the reason why Javascript, unlike other languages, uses
prototype instead of classical inheritance?
I know you can do classical inheritance with a bit of work, but it
seems like the kind of thing that would be nice out of the box, and I
don't understand why prototype is preferable.
Tom Longson (nym) http://igargoyle.com/ 5 1531 to*****@gmail.c om wrote: What is the reason why Javascript, unlike other languages, uses prototype instead of classical inheritance?
That is incorrect. JavaScript, and ECMAScript implementations in general,
are not the only programming languages around that support prototype-based
inheritance.
I know you can do classical inheritance with a bit of work,
You can only implement certain features of that.
but it seems like the kind of thing that would be nice out of the box,
That is probably what the creators of JavaScript 2.0, JScript 7.0 (.NET)
and ECMAScript 4 thought, too.
and I don't understand why prototype is preferable.
<URL:http://en.wikipedia.or g/wiki/Prototype-based_programmi ng> pretty
much covers the pros and cons. You should also search the archives at
groups.google.c om before you ask questions here. We had this before.
<URL:http://jibbering.com/faq/>
PointedEars
<to*****@gmail. com> wrote: What is the reason why Javascript, unlike other languages, uses prototype instead of classical inheritance?
http://wp.netscape.com/comprod/colum...vators_be.html
the original reasons are
"[...] If they're writing small pieces of code, they just want to get their
code
done with the minimal amount of fuss. Finally, we agreed that this new
language
should look like Java, but be a scripting language."
" Content creation should not be recondite. It should not be this bizarre
arcana
that only experts and gold-plated computer science gurus can do.
There are economic advantages to lowering the entry costs in creating
web content and in sharing it or aggregating it [...]"
a prototype-based language allowed that I know you can do classical inheritance with a bit of work, but it seems like the kind of thing that would be nice out of the box, and I don't understand why prototype is preferable.
you don't exactly do "classical inheritance" with JavaScript,
it look like it but in fact it is inheritance by delegation,
and imho it's not preferable or not, it's just a different way
of "thinking" or "doing".
What you can not do with prototype that you can do with class ?
zwetan to*****@gmail.c om wrote: What is the reason why Javascript, unlike other languages, uses prototype instead of classical inheritance?
I know you can do classical inheritance with a bit of work, but it seems like the kind of thing that would be nice out of the box, and I don't understand why prototype is preferable.
Tom Longson (nym) http://igargoyle.com/
I believe that the prototypal pattern has more expressive power than the
classical pattern.
Recall that Java had a crack as being the preferred language for writing
interactive applications in the browser. It failed there where JavaScript is now
succeeding.
People who have been trained in the classical pattern are often confused when
first exposed to prototypal ism. Don't let that bother you. It is worth
learning. It will also make you a better classical programmer. http://www.crockford.com/javascript to*****@gmail.c om wrote: What is the reason why Javascript, unlike other languages, uses prototype instead of classical inheritance?
Well, I'm a C++/c programmer at heart, as well as a reasonably
successfull javascript developer as well. The reason I mention that
is simply to provide some background into my perceptions.
As to specificly why the prototype approach was used over other methods
is something you'd have to address to the original developers, but
whatever their reason , it seems to work well enough for me.
One of the things I've noticed about javascript over time, is that
it functions very nicely as a versionless language.
If an array is is missing a member function like .pop() it does
not take much to detect same and prototype the missing function,
allowing your actual application code to function as if the Array.pop()
function had always been there.
This versionless ability is one of the things that really makes
javascript an interesting language to me.
I know you can do classical inheritance with a bit of work, but it seems like the kind of thing that would be nice out of the box, and I don't understand why prototype is preferable.
Again , I was not there when the team built the language, but
I can imagine that the versionless prototype concept was a big deal, and
that it's similarity to *classical* inheritance had a tendancy to
suppress the latter as being somewhat redundant.
I think it's something that grows on you as while keeping in mind
what you know from other languages , it seems to work best if
you give the language some room to mold your design process to
fit it's somewhat unique nature. It really is a nifty language,
and I give you that opinion against a backdrop of having developed
C++ since it's invention.
If you play with it for a while with an open mind, it really does
make a lot of sense, and while not the same as other languages
it is just as valid , and possibly more so in the context in
which it exists.
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
"Dr Clue" wrote: to*****@gmail.c om wrote:
[snip] I know you can do classical inheritance with a bit of work, but it seems like the kind of thing that would be nice out of the box, and I don't understand why prototype is preferable. Again , I was not there when the team built the language, but I can imagine that the versionless prototype concept was a big deal, and that it's similarity to *classical* inheritance had a tendancy to suppress the latter as being somewhat redundant.
from http://www.mozilla.org/js/language/
the "javascript at ten years" powerpoint have this phrase
"I hacked JS prototype in ~1 week in May"
and then on slide 5
" Design Goals
* Make it easy to copy/paste snippets of code
* Tolerate "minor" errors (missing semicolons)
* Simplified onclick, onmousedown, etc. event handling, inspired by
HyperCard
* Pick a few hard-working, powerful primitives
* First clas functions for procedural abstraction
* Objects everywhere, prototype-based
* Leave all elase out!
"
[snip] If you play with it for a while with an open mind, it really does make a lot of sense, and while not the same as other languages it is just as valid , and possibly more so in the context in which it exists.
and then slide 14
"
* Hackers discovered JS's FP and Self-ish OOP features
* And good hackers like those features
"
:)
zwetan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Elf M. Sternberg |
last post by:
One of the complaints about prototype.js (google for it if you're not
familiar with it) is that it's poorly documented. I have this inkling
that the key to understanding prototype.js is in the bind function.
The problem with Javascript is that the "this" operator is poorly
overloaded and it is often hard to understand in the context of
object-oriented javascript
So, let's start with the definition:
|
by: Robert |
last post by:
Hi,
I can use "with" like this:
function MyObject(message)
{
this.message = message;
}
function _MyObject_speak()
{
|
by: stephane |
last post by:
Hi all,
What I am trying to achieve is an 'inherits' method similar to Douglas
Crockford's (http://www.crockford.com/javascript/inheritance.html) but
that can enable access to the superclass' priviledged methods also. Do
you know if this is possible ?
In the following example, I create an ObjectA (variable a), an ObjectB
which inherits ObjectA (variable b) and an ObjectC which inherits
ObjectA (variable c1). The 'toString ()' method...
|
by: lkrubner |
last post by:
I'm reading an essay, I think one of Crockford's, and it has this
example in it:
function Demo() { }
Demo.prototype = new Ancestor();
Demo.prototype.foo = function () { } ;
Does Ancestor now have a function called foo?
What if I have 5 different objects, all descended from Ancestor? Do
|
by: Rob Somers |
last post by:
Hey people,
I read a good thread on here regarding the reason why we use function
prototypes, and it answered most of my questions, but I wanted to
double check on a couple of things, as I am writing something up on
functions, and I don't like writing about things I am not sure about.
Ok, then, here we go:
I initially thought that one would only really need to use a function
| |
by: eman1000 |
last post by:
I was recently looking at the prototype library
(http://prototype.conio.net/) and I noticed the author used the
following syntax:
Object.extend(MyObj.prototype, {
my_meth1: function(){},
my_meth2: function(){}
});
to define new methods on the MyObj prototype object. Object.extend
|
by: mmcloughlin |
last post by:
I'm learning about objects and am trying to figure out how basic
inheritance works. I've got into the habit of explicitly setting the
prototype object with an object literal as it seems to make the
creation of a class easier to read/understand.
Anyway it seems to break the inheritance chain in the following code
and I don't know why.
window.onload = function() {
|
by: Daz |
last post by:
Hi everyone.
My query is very straight forward (I think).
What's the difference between
someFunc.blah = function(){ ; }
and
|
by: burningodzilla |
last post by:
Hi all - I'm preparing to dive in to more complex application
development using javascript, and among other things, I'm having a hard
time wrapping my head around an issues regarding "inheritance" using
the prototype property. I realize there are no classes in JS, that code
therefore lives in objects instead of class definitions, and that
"inheritance" must be achieved prototypically and not classically.
That said, on with the code. Say I...
|
by: jacobstr |
last post by:
I've noticed Object.extend used in a few different ways and I'm having
trouble distinguishing why certain usages apply to a given situation.
On line 804 Ajax.Base is defined as follows:
Ajax.Base = function() {};
Ajax.Base.prototype = {
setOptions: function(options) { <...>
|
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...
| |
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...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |