Modular Javascript - Prototypal Pattern vs Classical OOP in JS

Publié le: 30 septembre 2015
sur la chaîne: LearnCode.academy
84,191
1.2k

While many JS devs still use classical OOP, many have switched to the prototypal pattern for Module Inheritance and Instantiation. Here's the prototypal pattern for JS and why some devs find it simpler to use.

View Classical Inheritance here:
   • Modular Javascript #6 - Classical Inherita...  

View the whole modular JS playlist here:
   • Modular Javascript  

SOURCE CODE HERE: http://codepen.io/anon/pen/gaggvG?edi...

Basically, when coding JS OOP with the prototypal pattern, everything is an object. You start with an object literal and, then, to inherit from it, you use Object.create(someModule) to create a child that inherits from it.

var parent = {some: method};
var child = Object.create(parent);
//now add new methods to the child
child.newMethod = someMethod;

So there's really no difference between inheritance and instantiation in the prototypal method. To create multiple children, simply:
var child1 = Object.create(parent);
var child2 = Object.create(parent);

And there you have it! Also see the source javascript code on how to include a create method so creating is a little more seamless.

~-~~-~~~-~~-~
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
   • Responsive Design Tutorial - Tips for maki...  
~-~~-~~~-~~-~


Sur cette page du site, vous pouvez voir la vidéo en ligne Modular Javascript - Prototypal Pattern vs Classical OOP in JS durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur LearnCode.academy 30 septembre 2015, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 84,191 fois et il a aimé 1.2 mille téléspectateurs. Bon visionnage!