Created
March 24, 2018 00:09
-
-
Save Dammmien/5c821e8c6bc64c571048b0215a34b674 to your computer and use it in GitHub Desktop.
JavaScript Prototype design 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
class Sheep { | |
constructor(name, weight) { | |
Object.assign(this, { name, weight }); | |
} | |
clone() { | |
return new Sheep(this.name, this.weight); | |
} | |
} | |
const bob = new Sheep('Bob', 80); | |
const copyOfBob = bob.clone(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment