Skip to content

Instantly share code, notes, and snippets.

@sairion
Created November 14, 2016 06:41
Show Gist options
  • Save sairion/69f7e0e9da58a9995e6a2e7e0d1162cc to your computer and use it in GitHub Desktop.
Save sairion/69f7e0e9da58a9995e6a2e7e0d1162cc to your computer and use it in GitHub Desktop.
{// scoped
class A {
a () { return 1 }
}
// wraps existing function
function baseWrapApplier(theConstructor, appliyingKey, descriptor) {
if (theConstructor.prototype[appliyingKey]) {
}
return function WrapApplierConstructor(constructorArgs) {
const obj = Object.create(theConstructor.prototype)
return Object.defineProperty(obj, appliyingKey, descriptor)
}
}
function wrapApplier(theConstructor, appliyingKey, value) {
return baseWrapApplier(theConstructor, appliyingKey, { value })
}
const A2 = wrapApplier(A, 'a', function a(){ return 2; })
const a = new A2
console.log(a.a())
console.assert(a.a() === 2, 'Failed: value is', a.a())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment