known icon indicating copy to clipboard operation
known copied to clipboard

Known as a class decorator

Open eranimo opened this issue 8 years ago • 5 comments

eranimo avatar Jul 07 '16 15:07 eranimo

Can you elaborate?

sindresorhus avatar Jul 07 '16 19:07 sindresorhus

The ability to use this as a class decorator:

@known
class Foobar {
    baz = 1;
    someMethod() {}
}
Foobar.crap
> [TypeError] Unknown property: crap

eranimo avatar Jul 08 '16 01:07 eranimo

That would indeed be very nice, but decorators is just an ECMAScript stage 1 proposal at the moment.

https://github.com/wycats/javascript-decorators/blob/master/README.md

Would be happy to accept a pull request if it's possible to support it without transpiling this code though.

sindresorhus avatar Jul 08 '16 09:07 sindresorhus

A decorator is just a function with a pre-defined set of arguments. So it should be perfectly possible.

SamVerschueren avatar Jul 08 '16 09:07 SamVerschueren

Hey guys, I'm trying to pick this up but i'm sure if i got the gist of it. Since transpiling is out of the question, wouldnt wrapping it in high order function result in the same invocation, like

known([random class here]).

Thank you

pedromrb avatar May 04 '17 08:05 pedromrb