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
<[email protected]> wrote:
>
>
> On Tue, Sep 27, 2011 at 8:09 PM, Nick Morgan <[email protected]> wrote:
>>
>> On 27 September 2011 17:25, Lasse Reichstein <[email protected]>
>> 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/[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]
>

-- 
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]

Reply via email to