473,408 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Why Prototype?

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/

Jan 9 '06 #1
5 1508
to*****@gmail.com 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.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
Jan 9 '06 #2

<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



Jan 10 '06 #3
to*****@gmail.com 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
Jan 10 '06 #4
to*****@gmail.com 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
--.
Jan 11 '06 #5

"Dr Clue" wrote:
to*****@gmail.com 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
Jan 11 '06 #6

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

Similar topics

8
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...
8
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
2
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'...
4
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...
21
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...
13
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(){},...
6
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...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
6
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"...
3
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: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.