Why Prototype?

T

tomlong

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/
 
T

Thomas 'PointedEars' Lahn

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.org/wiki/Prototype-based_programming> pretty
much covers the pros and cons. You should also search the archives at
groups.google.com before you ask questions here. We had this before.

<URL:http://jibbering.com/faq/>


PointedEars
 
Z

zwetan

What is the reason why Javascript, unlike other languages, uses
prototype instead of classical inheritance?

http://wp.netscape.com/comprod/columns/techvision/innovators_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
 
Z

zwetan

Dr Clue said:
(e-mail address removed) 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
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top