JavaScript Best Practices – Using Prototypes




In this video, follow along with expert author Jeremy McPeak as he explains how to use JavaScript prototypes. For more information about the course, as well as more free lessons, visit http://oreil.ly/2p4CweU.

When you’re creating multiple objects, Jeremy explains that you should look for the things that could be considered a prototype – things that don’t change, functions for example, or anything that an object would need but is never, or rarely, modified.

This course helps you transition from JavaScript novice to JavaScript pro by teaching you the techniques and practices used by the seasoned practitioner.

Facebook: https://www.facebook.com/OReilly/?fref=ts
Twitter: https://twitter.com/OReillyMedia
Website: http://www.oreilly.com/

Original source


21 responses to “JavaScript Best Practices – Using Prototypes”

  1. So, the only way to access johnDoe's greet() method is via another person object "janeSmith". That seems weird. I want to call greet() method as johnDoe.greet() and it should printout "john". That is more natural.

  2. 7:22 If you want to make the code even more wierd, you can return the person object directly, by changing row: 8 to this:
    return person = Object.create(personPrototype, {
    And remove the return person; statement on row:15

  3. I like to create modules with all static functions, with one of them being a special "constructor" function for creating instance objects that the module works with. Then I just pass those instance objects as an argument to any static function that needs to work with instance data. So there's just one static version of all functions and simple data-only objects, without having to mess with ugly Object.prototype.whatever code.

Leave a Reply