-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification on proposed meta information #12
Comments
Differentiating between a function and a method is important because of |
I think that Could you give realistic examples/use cases, where this distinction is important? |
The decorator might want to install a function that uses |
Unfortunately it may not. At least not now: $ node
> x = function () { super.x(123); };
x = function () { super.x(123); };
^^^^^
SyntaxError: 'super' keyword unexpected here
> Any attempt to create a function with The same goes for copying member functions between prototypes: $ node
> class A { x() { console.log('*** class A method x()'); } }
[Function: A]
> class B extends A { x() { super.x(); } }
[Function: B]
> new B().x();
*** class A method x()
undefined
> class C {}
[Function: C]
> C.prototype.x = B.prototype.x
[Function: x]
> new C().x();
*** class A method x()
undefined
> The example above demonstrates that a static (one-time) binding is used as per the spec, and copying does not change that. If the proposal includes things, which are impossible at the moment, please at least mention them in the documentation — I've read all of it thoroughly and do not recall seeing anything like that. Unless it is proposed to change, my reasoning stays, and the question "why so complex?" remains. |
There are a couple reasons why I separated out method/field kinds:
I'm not sure how to unify them given these differences. A kind field is also a sort of future-proofing in case more differences come up in the future. The way that methods have special rights for |
I don't see a way to make a dictionary that includes private class elements. |
I don't really see any actions to take for this bug; the suggestions seem to really be around the ergonomics of the decorator functions themselves, which I don't think have to be the prettiest, and I've explained the design rationale above. |
TAXONOMY and METAPROGRAMMING define a structure to describe a decorated element:
It appears that
kind
is largely redundant: it can be derived from a property descriptor:Granted that someone can define a field initialized with a function, but it is … a method for all intents and purposes, and probably should be treated as such.
"Class decorators are passed in an Array of all class elements". Why exactly? To check elements by names linearly? To have them unsorted by placement? It appears that if we re-use an existing structure we gain utility and simplicity. I am talking about a dictionary of property descriptors consumed directly by Object.defineProperties() and Object.create(). If a class decorator receives three objects corresponding their placement, and can modify them in place, it will simplify a lot of things. (Obviously a class decorator needs to know the base class as well.)
Example: verify that
render()
is defined, add a default implementation otherwise:The example above is trivial. The array version will be less readable and much slower.
Example: do-it-yourself class in a class decorator:
Again, all code above is a small collection one-liners. The only non-trivial part is to generate a constructor, which will call the base, initialize own properties, and call a user-defined custom constructing code. It should be done anyway is a part of this proposal.
The proposal mentions, but does not define, a class finisher. The code above could very well be a spec for the default finisher.
Example: go back to the original array of elements:
Isn't it simpler and more flexible this way than an array of elements?
The text was updated successfully, but these errors were encountered: