On 28 September 2011 11:01, Jarek Foksa <[email protected]> wrote: > If I have undertood you correctly, in purely prototypical paradigm I > would skip the creation of Human and Man "classses" becaues they are > generalisation and don't represent single things and start right away > from defining 'john' instance like this; > > var john = { > legs: 2, > hands: 2, > eyes: 2, > canTalk: true, > sayHello: function() { > alert('hello'); > } > } > > Then if I wanted to create e.g. cat, which is also a mammal so it > shares some characteristics with john, I would simply base it on john: > > var cat = Object.extend(john, { > legs: 4, > hands: 0, > canTalk: false, > canMeow: true, > meow: function() { > alert('meow'); > } > } > > Then a dog object could be based on cat (because dogs share more > characteistics with cats than with humans): > > var dog = Object.extend(cat, { > canMeow: false, > } > > I'm not really sure if this is a good idea. E.g. now the dog will have > sayHello() and meow() methods. > Considering the fact that dogs don't talk nor meow, should I be > overwritting those methods to undefined in dog object? > > Do you know of any medium or big project written this way? >
No I don't. But I've never programmed in a purely prototypal language either. I'd like to so I can get some ideas as to *how* to do proper prototypal inheritance in JS. I'm interested to see JavaScript written in a way that doesn't get overloaded with excessive class-based baggage. -- Nick Morgan http://skilldrick.co.uk @skilldrick Save our in-boxes! http://emailcharter.org -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
