Thursday, October 16th, 2008
Another look at JavaScript inheritance
<p>Stoyan Stefanov of Yahoo! has published a nice article on JavaScript's class-less objects.This is published on JavaRanch, so it talks to the Java community, and uses that lense to explain the differences.
He delves into:
- Constructor functions
- Function objects and prototype property
- Inheritance via the prototype
- Inheritance by copying properties
- Crockford's beget object:
JAVASCRIPT:
-
-
function begetObject(o) {
-
function F() {}
-
F.prototype = o;
-
return new F();
-
}
-
-
- YUI's extend()
Related Content:











A very nice explanation of the javascript way of doing things for folks being used to statically typed languages. Where was that article four years ago? It really would have made things easier for me. ;)
Thanks Carrion, you made my day ;)
Nice and clear focus into javascript inheritance, thank you for sharing Stoyan.
As specified in one of my recent posts, the Douglas Crockford function does not need a new function for each object, since inheritance is via assigned prototype and not via new functions :-)
Object.create = function(Function){
// WebReflection Revision
return function(Object){
Function.prototype = Object;
return new Function;
}}(function(){});
In any case, nice article