Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Created March 24, 2018 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dammmien/5c821e8c6bc64c571048b0215a34b674 to your computer and use it in GitHub Desktop.
Save Dammmien/5c821e8c6bc64c571048b0215a34b674 to your computer and use it in GitHub Desktop.
JavaScript Prototype design pattern
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