Skip to content

Instantly share code, notes, and snippets.

@k1r0s
Last active April 15, 2018 15:16
Show Gist options
  • Select an option

  • Save k1r0s/a8856c9ee69df54c1f84a375f8c00fa4 to your computer and use it in GitHub Desktop.

Select an option

Save k1r0s/a8856c9ee69df54c1f84a375f8c00fa4 to your computer and use it in GitHub Desktop.
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
@imrajuahamed
Copy link

nice

@imrajuahamed
Copy link

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