Last active
April 15, 2018 15:16
-
-
Save k1r0s/a8856c9ee69df54c1f84a375f8c00fa4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const sayHello = () => console.log("hello") | |
| function instanceFinisher(somethingToHappen) { | |
| return function (target) { | |
| const orig = target | |
| target = (...args) => { | |
| setTimeout(somethingToHappen) | |
| orig.apply(this, args) | |
| } | |
| return target | |
| } | |
| } | |
| @instanceFinisher(sayHello) | |
| class A { | |
| constructor() { | |
| console.log("A constructor"); | |
| } | |
| } | |
| class B extends A { | |
| constructor() { | |
| super(); | |
| console.log("B constructor"); | |
| } | |
| } | |
| new B |
const sayHello = () => console.log("hello")
function instanceFinisher(somethingToHappen) {
return function (target) {
const orig = target
target = (...args) => {
setTimeout(somethingToHappen)
orig.apply(this, args)
}
return target
}
}
@instanceFinisher(sayHello)
class A {
constructor() {
console.log("A constructor");
}
}
class B extends A {
constructor() {
super();
console.log("B constructor");
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice