July 2018
Beginner to intermediate
374 pages
8h 54m
English
In real life, you copy a cool idea or an interesting device by duplicating everything it does and changing a few things here and there to make it even better. The thing you’re copying becomes the prototype for the new way of doing it. JavaScript handles copying objects in a similar way.
To describe another movie, we can copy the prototypical bestMovie object with Object.create().
| | var greatMovie = Object.create(bestMovie); |
| | greatMovie.logMe(); |
| | // => Star Wars, starring: Mark Hamill,Harrison Ford,Carrie Fisher |
Object.create() will create a new object with all the same properties and methods as the prototypical object we created earlier. So the new object, greatMovie, has the same title and actors as the original bestMovie ...
Read now
Unlock full access