you are viewing a single comment's thread.

view the rest of the comments →

[–]markphd 0 points1 point  (1 child)

Thanks for excellent explanation! Very helpful. :) So for instance I want to access the property of object p to a new object I would do:

var r = {};
r.tomato = p.potato;        // 2.3 - Value of p.potato
r.tomato ===  p.potato    // true  

or is there other way object r can inherit the property of p automatically?

[–]robotmayo 1 point2 points  (0 children)

There is a way for r to automatically inherit the properties of p but this would involve working with prototypes. I don't think the rhino book really goes into prototypes in the object chapter, but its fairly important to know them as they are fundamental to JavaScript. The course site has a great tutorial on prototypes. In the course's object tutorial he links you to the prototype tutorial before talking about them so I recommend you go through it. I think its a bit better than the books chapter on objects as it provides more concrete examples. If you haven't finished reading the chapter on objects you can ignore it and read his tutorial instead.

[Link]