Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- нужно реализовать паттерн chaining
- написать функцию createHash
- которая сможет работать вот так:
- createHash()
- .set('3', 2)
- .set('4', 5)
- .remove('3')
- .getValues() // {'4': 5}
- */
- class Hash {
- #obj
- constructor() {
- this.#obj = {};
- }
- set(key, value) {
- this.#obj[key] = value;
- return this;
- }
- remove(key) {
- delete this.#obj[key];
- return this;
- }
- getValues() {
- return this.#obj;
- }
- };
- createHash = () => {
- return new Hash();
- }
- hash = createHash().set('3', 2).set('4', 5).remove('3').set('3', 10);
- console.log(hash.getValues());
- hash.obj = {anyValue: 4};
- console.log(hash.getValues());
Advertisement
Add Comment
Please, Sign In to add comment