javascript-decorators icon indicating copy to clipboard operation
javascript-decorators copied to clipboard

Decorators that works on instance but not specified on method / property

Open otakustay opened this issue 10 years ago • 2 comments

Sometime we need a decorator to work on instance (not class itself), but we do not have any method / property for it, these usually comes with metadata additions:

function foo(value) {
    return function (target) [
        (target.meta || (target.meta = {})).foo = value;
    }
}

Such decorators only add additional metadata so it can be used in runtime. I know it could be archived with class decorator and class inheritance but it's really not that intuitive.

I propose decorators could be used on constructor, which works when an instance is created just like method decorators, but constructor decorators does not descriptor argument, and the key argument is "constructor"

otakustay avatar May 31 '15 17:05 otakustay

Possible duplicate: https://github.com/wycats/javascript-decorators/issues/13

megawac avatar May 31 '15 17:05 megawac

:+1: I'll be also interested in decorators on POJOs to be able to enhance more than one method with a decorator.

troch avatar Jul 10 '15 13:07 troch