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 great_movie, 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 (star_wars) object, including the year, 1977!

We can also use a simple function to build objects in JavaScript—yes, the simple function that we first saw all the way back in Chapter 5, Functions: Use and Use Again. Surprisingly, we don’t have to do anything special ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.