Skip to content

Instantly share code, notes, and snippets.

@andrewborisov
Created July 24, 2020 04:57
Show Gist options
  • Save andrewborisov/e2d99f415b15f6f86c70b833ded8ac44 to your computer and use it in GitHub Desktop.
Save andrewborisov/e2d99f415b15f6f86c70b833ded8ac44 to your computer and use it in GitHub Desktop.
Гист для статьи "Еще раз о паттернах проектирования в Javascript es6"
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