tags:

views:

50

answers:

1

In javascript what sort of inheritence do you favour? The ECMA standard is to use prototpye chaining. So I just set the prototype of the object that's doing the inheriting (monkey) to invoke a new instance of the object I want to inherit from (animal):

monkey.prototype = new animal();

I am aware there are other ways to achieve inheritence. i.e inheriting only the prototype, Parastic inheritence, deep copy, shallow copy.

Can anyone enlighten me and tell me if there is one in particular I should use? ONe that has benefits that outweigh the other methods.

+2  A: 

Theres a lot better article on it here than I could ever write. http://www.crockford.com/javascript/inheritance.html

In general it depends on what you want to achieve. In general though I think duck typing is what is considered best for javascript.

Wes
Sorry, What's duck typing?
elduderino
@elduderino, http://en.wikipedia.org/wiki/Duck_typing
Gaby