{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/proposal-decorators/issues/58","repository_url":"https://api.github.com/repos/tc39/proposal-decorators","labels_url":"https://api.github.com/repos/tc39/proposal-decorators/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/tc39/proposal-decorators/issues/58/comments","events_url":"https://api.github.com/repos/tc39/proposal-decorators/issues/58/events","html_url":"https://github.com/tc39/proposal-decorators/issues/58","id":299899302,"number":58,"title":"Document element finishers in metaprogramming guide","user":{"login":"mbrowne","id":874316,"avatar_url":"https://avatars0.githubusercontent.com/u/874316?v=4","gravatar_id":"","url":"https://api.github.com/users/mbrowne","html_url":"https://github.com/mbrowne","followers_url":"https://api.github.com/users/mbrowne/followers","following_url":"https://api.github.com/users/mbrowne/following{/other_user}","gists_url":"https://api.github.com/users/mbrowne/gists{/gist_id}","starred_url":"https://api.github.com/users/mbrowne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbrowne/subscriptions","organizations_url":"https://api.github.com/users/mbrowne/orgs","repos_url":"https://api.github.com/users/mbrowne/repos","events_url":"https://api.github.com/users/mbrowne/events{/privacy}","received_events_url":"https://api.github.com/users/mbrowne/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-24T01:42:02Z","updated_at":"2018-03-10T12:55:44Z","closed_at":null,"author_association":"NONE","body":"After reading the proposal more carefully, I realized that there are element finishers in addition to class finishers. Assuming that this feature is likely to stay in the proposal (which I hope it is), I propose adding an example to METAPROGRAMMING.MD.\r\n\r\nI can submit a PR for this, I just wanted to post this issue first to verify that I understand correctly and that `finisher` is indeed one of the valid properties you can set on the element descriptor object that you return. I was thinking I'd use the `@readonly` decorator I mentioned in #55 as the example:\r\n\r\n    class User {\r\n      @readonly id\r\n      ...\r\n\r\n      constructor(id = null) {\r\n        this.id = id\r\n      }\r\n    }\r\n    \r\n    function readonly(elementDecriptor) {\r\n        elementDecriptor.finisher = () => {\r\n            elementDecriptor.descriptor.writable = false\r\n        }\r\n        return elementDecriptor\r\n    }\r\n\r\nFor now I can keep my PR limited to METAPROGRAMMING.MD; I assume it's ok to include an additional example there that isn't necessarily in the readme file.\r\n\r\nI was also wondering about this section of the metaprogramming guide:\r\n\r\n    {\r\n      kind: \"method\" or \"field\"\r\n      key: String, Symbol or Private Name,\r\n      placement: \"static\", \"prototype\" or \"own\",\r\n      descriptor: Property Descriptor (argument to Object.defineProperty),\r\n    }\r\n\r\nWould it be accurate to include `initializer` and `finisher` in that list as well? Or are those only properties that you can return, not properties that are necessarily already included in the object that gets passed in? I wasn't sure if maybe the object already includes those properties but they're just undefined by default. (And in the case of initializers I'm guessing that if you initialize your field with something like `class MyClass { x = 1 }` that it would already have an initializer setting the value to 1 that your decorator could override/extend if it wanted to.)"},"comment":{"url":"https://api.github.com/repos/tc39/proposal-decorators/issues/comments/372027747","html_url":"https://github.com/tc39/proposal-decorators/issues/58#issuecomment-372027747","issue_url":"https://api.github.com/repos/tc39/proposal-decorators/issues/58","id":372027747,"user":{"login":"mbrowne","id":874316,"avatar_url":"https://avatars0.githubusercontent.com/u/874316?v=4","gravatar_id":"","url":"https://api.github.com/users/mbrowne","html_url":"https://github.com/mbrowne","followers_url":"https://api.github.com/users/mbrowne/followers","following_url":"https://api.github.com/users/mbrowne/following{/other_user}","gists_url":"https://api.github.com/users/mbrowne/gists{/gist_id}","starred_url":"https://api.github.com/users/mbrowne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbrowne/subscriptions","organizations_url":"https://api.github.com/users/mbrowne/orgs","repos_url":"https://api.github.com/users/mbrowne/repos","events_url":"https://api.github.com/users/mbrowne/events{/privacy}","received_events_url":"https://api.github.com/users/mbrowne/received_events","type":"User","site_admin":false},"created_at":"2018-03-10T12:55:44Z","updated_at":"2018-03-10T12:55:44Z","author_association":"NONE","body":"Oops, I meant to post my previous comment in the other issue I created, #55. But I also have a question related to this issue...\r\n\r\nIf the user wanted to modify a class's prototype (e.g. manually add a new field to the prototype) in a finisher function for some reason, would that be possible? For example:\r\n\r\n    function myFieldDecorator(elementDescriptor) {\r\n        assert(elementDescriptor.kind == \"field\");\r\n        elementDescriptor.finisher(klass) {\r\n            klass.prototype.foo = 1\r\n        }\r\n    }\r\n\r\nI read this in the RunClassFinishers section of the proposal:\r\n\r\n    Call( finisher, undefined, « constructor »)\r\n\r\nBut it's unclear to me whether or not the decorator is able to modify the prototype at this point. I would guess so, just making sure...thank you."}}
{"actor":{"display_login":"mbrowne"}}