Skip to content

Commit f62fcd1

Browse files
committed
Add extended examples
1 parent d26239e commit f62fcd1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

JavaScript/3-extended.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const listener = Parent => class extends Parent {
4+
constructor() {
5+
super();
6+
this.events = {};
7+
}
8+
on(name, listener) {
9+
const event = this.events[name];
10+
if (event) event.push(listener);
11+
else this.events[name] = [listener];
12+
}
13+
emit(name, ...data) {
14+
const event = this.events[name];
15+
if (!event) return;
16+
event.forEach(fn => fn(...data));
17+
}
18+
};
19+
20+
const adder = Parent => class extends Parent {
21+
constructor(initial) {
22+
super();
23+
this.value = initial;
24+
}
25+
add(value) {
26+
this.value += value;
27+
return this;
28+
}
29+
};
30+
31+
console.dir({
32+
listener,
33+
adder
34+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy