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 ...

Get 3D Game Programming for Kids, 2nd Edition 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.