Skip to content

Instantly share code, notes, and snippets.

@silkentrance
Last active February 22, 2016 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silkentrance/8133476645f9ce7bcf5b to your computer and use it in GitHub Desktop.
Save silkentrance/8133476645f9ce7bcf5b to your computer and use it in GitHub Desktop.
Example impl
import util from 'util';
function hypotheticalDecoratorThatMerges(target, key, descriptor)
{
let result = descriptor;
if ('get' in descriptor || 'set' in descriptor)
{
const desc = {};
Object.keys(descriptor).forEach(
function (k)
{
desc[k] = descriptor[k];
});
let superclass;
let supertarget;
if (typeof target == 'function')
{
superclass = Object.getPrototypeOf(target);
supertarget = superclass;
}
else
{
superclass = Object.getPrototypeOf(target.constructor);
supertarget = superclass.prototype;
}
let superdesc = Object.getOwnPropertyDescriptor(supertarget, key);
if (!descriptor.set && superdesc.set)
{
desc.set = function (v) { superdesc.set.apply(this, v); };
}
if (!descriptor.get && superdesc.get)
{
desc.get = function () { return superdesc.get.apply(this); };
}
desc.enumerable = desc.enumerable && superdesc.enumerable;
desc.configurable = desc.enumerable && superdesc.configurable;
console.log(util.inspect(superdesc));
console.log(util.inspect(desc));
result = desc;
}
return result;
}
export class Base
{
get name() {}
set name(v) {}
}
export class Derived extends Base
{
@hypotheticalDecoratorThatMerges
set name(v) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment