I think the case with purely prototypical is that you delay the abstraction. I 
am not an expert at all, but as I understand it in your example you would start 
with john: 

var john = {
 legs: 2,
 hands: 2,
 eyes: 2,
 canTalk: true,
 sayHello: function() {
 alert('hello');
 }
}

Then if you see the need of a cat object, and you notice some shared behaviour 
with john you would abstract that:

var mamal = { legs: 0, hands:0, eyes: 2};
var john = Object.extend(mamal, { legs:2, hands: 2, canTalk: true, sayHello: 
function() { alert('Hello'); } });
var cat  = Object.extend(mamal, { legs:4, canMeow: true, meow: function() { 
alert('meow'); } });



Cheers, 
Alexandre Gravem

On quarta-feira, 28 de setembro de 2011 at 07:01, Jarek Foksa 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?
> 
> On Wed, Sep 28, 2011 at 10:22 AM, Lasse Reichstein
> <reichsteinatw...@gmail.com (mailto:reichsteinatw...@gmail.com)> wrote:
> > 
> > 
> > On Tue, Sep 27, 2011 at 8:09 PM, Nick Morgan <skilldr...@gmail.com 
> > (mailto:skilldr...@gmail.com)> wrote:
> > > 
> > > On 27 September 2011 17:25, Lasse Reichstein <reichsteinatw...@gmail.com 
> > > (mailto:reichsteinatw...@gmail.com)>
> > > wrote:
> > > 
> > > > Also, when doing pure object-based design, you have to keep your
> > > > categories
> > > > clear. Your Human and Man objects are clearly prototype objects, not
> > > > instance objects. They are meant to be inherited, not used directly. The
> > > > object you create with Object.create(Man) is an instance object
> > > > representing
> > > > a single man. There is nothing distinguishing them in the code,
> > > > though. Constructor functions holding prototype objects does that for
> > > > you.
> > > > /L
> > > 
> > > I don't understand what you're saying here. You'd only use
> > > Object.create to create instances based on other instances, not on
> > > constructor functions. So you don't need to keep categories clear -
> > > everything is an object, there are no constructor functions. Or am I
> > > missing something?
> > 
> > My point is that while everything is an object, not all objects are equal.
> > Objects have meaning. The meaning of the Human object is to represent the
> > common things of all humans. The meaning of the Man object is to represent
> > the common things of all men. The meaning of the john object is to represent
> > a single man.
> > If some code expects an object representing a single man (and such code will
> > exist) it would be a category error to pass it the Man object.
> > This is really class-based thinking: Classes represent groups of things,
> > instances represent single things. And this is how your code is structured -
> > class based, just without any syntactic help in distinguishing "class
> > objects" from "instance objects".
> > If you are writing class based structures, you might as well take advantage
> > of the built-in support for that. It makes your code much more readable, and
> > it also happens to be faster.
> > If you went completely object-based, you could just create a prototype human
> > object representing a single human, which could be john, and then create
> > other humans by modifications relative to john. Then all you have are
> > instance objects with no generalizations - instance objects created based on
> > other instance objects.
> > /L
> > 
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/jsmentors@jsmentors.com/
> > 
> > To search via a non-Google archive, visit here:
> > http://www.mail-archive.com/jsmentors@googlegroups.com/
> > 
> > To unsubscribe from this group, send email to
> > jsmentors+unsubscr...@googlegroups.com 
> > (mailto:jsmentors+unsubscr...@googlegroups.com)
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/jsmentors@jsmentors.com/
> 
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/jsmentors@googlegroups.com/
> 
> To unsubscribe from this group, send email to
> jsmentors+unsubscr...@googlegroups.com 
> (mailto:jsmentors+unsubscr...@googlegroups.com)

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to