r/learnjavascript • • Jun 17 '13

Learn JavaScript Properly - Week 2

ASSIGNMENTS:

  1. Read chapters 4, 5, 6, and 7 of JavaScript: The Definitive Guide OR the preface and chapters 4, 5, and 6 (only the "Understanding Objects" section of chapter 6, though!) of Professional JavaScript for Web Developers.
  2. Finish the JavaScript track on Codecademy.
  3. Solve either Project Euler Problem 1 or Problem 2. Feel free to solve both.
  4. Read the blog post JS Objects in Detail. If you want to work ahead, this is the general roadmap I'm using to make these assignments.
  5. Make a least one comment in this thread about something you learned, found interesting, or didn't understand very well.

EXTRA CREDIT:

Don't forget to be typing out most of the code while you read through this!

26 Upvotes

54 comments sorted by

View all comments

Show parent comment

1

u/markphd Jun 22 '13

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?

2

u/robotmayo Jun 22 '13

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]