...

View Full Version : JavaScript | prototypal inheritance vs. classical inheritance



andymoles
12-29-2010, 07:27 AM
What are the benefits of prototypal inheritance over classical inheritance?

amtindia
12-29-2010, 07:47 AM
In My Opinion, the major benefit of prototypal inheritance is its simplicity.

The prototypal nature of the language can confuse people who are classically trained, but it turns out that actually this is a really simple and powerful concept, differential inheritance (http://en.wikipedia.org/wiki/Differential_inheritance).

You don't need to make classification, your code is smaller, less redundant, objects inherit from other, more general objects.

If you think prototypically you will soon notice that you don't need classes...

Prototypal inheritance will be much more popular in the near future, the ECMAScript 5th Edition (http://www.ecma-international.org/publications/standards/Ecma-262.htm) specification introduced the Object.create method, which allows you to produce a new object instance that inherits from another one in a really simple way:


var obj = Object.create(baseInstance);
This new version of the standard is being implemented by all browser vendors, and I think we will start to see more pure prototypal inheritance...


Warm Regards,
Aby Varghese
Director at AMT (http://www.amt.in)

oesxyl
12-29-2010, 11:36 AM
What are the benefits of prototypal inheritance over classical inheritance?

why you post twice? this is confusing. Please ask one of the moderators to join this thread with http://www.codingforums.com/showthread.php?t=213444

best regards and happy holidays

rnd me
12-29-2010, 07:05 PM
String.prototype.tag=function(a){
return ["<",a,">",this,"</",a,">"].join("");
}

"this is a text phrase".split("").reverse(
).join("").toUpperCase().tag("span");

//==<span>ESARHP TXET A SI SIHT</span>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum