Last active
December 17, 2015 00:59
-
-
Save DForshner/5525304 to your computer and use it in GitHub Desktop.
JavaScript Prototype Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Prototype pattern allows objects to be created | |
// based on a template of an existing object using cloning. | |
var Dragon = { | |
name: "TROGDOR" | |
}; | |
//Object.create takes its first argument and applies it to the prototype of your new object. | |
var myDragon = Object.create(Dragon); | |
console.log(myDragon.name); | |
myDragon.name = "TROGDOR the burninator!"; | |
console.log(myDragon.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment