Created
July 24, 2020 04:57
-
-
Save andrewborisov/e2d99f415b15f6f86c70b833ded8ac44 to your computer and use it in GitHub Desktop.
Гист для статьи "Еще раз о паттернах проектирования в Javascript es6"
This file contains 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 Prototype { | |
setOption(key, val) { | |
this[key] = val; | |
} | |
clone() { | |
const clone = new Prototype(); | |
const keys = Object.keys(this); | |
keys.forEach((k) => clone.setOption(k, this[k])); | |
return clone; | |
} | |
} | |
// Code for the testing | |
const testing = () => { | |
const proto1 = new Prototype(); | |
proto1.setOption('option1', '1'); | |
const clone1 = proto1.clone(); | |
clone1.setOption('option2', '2'); | |
const clone2 = clone1.clone(); | |
clone2.setOption('option3', '3'); | |
console.log(proto1, clone1, clone2); | |
}; | |
testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment