Constructing New Objects
We now have a good idea of what an object is in JavaScript. We also now see how an object can be a prototypical object and act as a template for creating similar objects. Creating new objects like this can be pretty tedious and mistake-prone. Consider this: if we forget to assign the year property on greatMovie, then the object will think Toy Story was made back in 1977. Unless we tell the object differently, it copies all properties from the original (bestMovie) object, including the year, 1977!
Another way to create objects in JavaScript is using simple functions. Yes, the same simple functions that we first saw all the way back in Chapter 5, Functions: Use and Use Again. Surprisingly, we don’t have to do anything ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access