Hacker News new | past | comments | ask | show | jobs | submit login

I have a Java background and I don't really use JavaScript, but I'd like to understand something :

var man = fromPrototype(person, { sex: "male" });

After this code runs, we have a reference to a function (man) inside which we declare an object (newObject) for which we define the new property (sex). That means we can now call newObject.sex

But later he's calling that property on the function itself : jeremy.sex

How is this possible?




His example has an error. He forgot to return newObject at the end of the fromPrototype function. The fromPrototype function returns an instance (an object) that inherits from the given prototype and with the same properties you passed in with the object.


Thanks.


It seems that fromPrototype is missing a line:

  return newObject;
'man' and 'jeremy' are objects, not functions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: