{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/52","repository_url":"https://api.github.com/repos/tc39/proposal-private-fields","labels_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/52/comments","events_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/52/events","html_url":"https://github.com/tc39/proposal-private-fields/issues/52","id":176926198,"number":52,"title":"Accessing private fields without the need of a sigill","user":{"login":"dfahlander","id":6791329,"avatar_url":"https://avatars.githubusercontent.com/u/6791329?v=3","gravatar_id":"","url":"https://api.github.com/users/dfahlander","html_url":"https://github.com/dfahlander","followers_url":"https://api.github.com/users/dfahlander/followers","following_url":"https://api.github.com/users/dfahlander/following{/other_user}","gists_url":"https://api.github.com/users/dfahlander/gists{/gist_id}","starred_url":"https://api.github.com/users/dfahlander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfahlander/subscriptions","organizations_url":"https://api.github.com/users/dfahlander/orgs","repos_url":"https://api.github.com/users/dfahlander/repos","events_url":"https://api.github.com/users/dfahlander/events{/privacy}","received_events_url":"https://api.github.com/users/dfahlander/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2016-09-14T14:42:13Z","updated_at":"2016-11-09T21:38:47Z","closed_at":null,"body":"As discussed in #14, many people advocates for using the `private` keyword for declaring the private fields. But that discussion has went on further into how we should access the properties. It seems that the sigill (# or @) is something that could also be questioned for _accessing_ the fields. So let's bring that up in this separate issue.\n\n@eggers came with a very interesting solution that I've been examiniting a little. It allows private access without a sigill and without changing the property lookup algorithm in any way. My own working example can be found [here](https://jsfiddle.net/dfahlander/2jrurbx3/) - uses a WeakMap to store the properties. You need a modern browser to open it!\n\nThis way, it would be possible to:\n- Access private properties precisely the same way as public ones.\n- Shared namespace between private and public properties (as in other languages) (don't know if this is good or bad though)\n\n...but also:\n- Allow this-less access to private properties from class lexical scope (optional 'addon' to the idea).\n- Let developer choose when to use this.x and just x.\n\n_EDIT: this-less access would also make optimization possible because it would be obvious at parse time what property is being accessed and the parser already knows that it is allowed and can omit having to check against the white-list_\n\n``` js\nclass A {\n    private buffer, pos;\n\n    method () {\n        buffer[pos++] = 'hello'; // instead of this.buffer[this.pos++] = 'hello'.\n    }\n}\n```\n\nAnother sample:\n\n``` js\n\nclass Greeter {\n    private greeting;\n\n    constructor (greeting) {\n        this.greeting = greeting;\n    }\n\n    greet () {\n        return greeting; // Or this.greeting\n    }\n}\n\n```\n"},"comment":{"url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/comments/259533955","html_url":"https://github.com/tc39/proposal-private-fields/issues/52#issuecomment-259533955","issue_url":"https://api.github.com/repos/tc39/proposal-private-fields/issues/52","id":259533955,"user":{"login":"littledan","id":189835,"avatar_url":"https://avatars.githubusercontent.com/u/189835?v=3","gravatar_id":"","url":"https://api.github.com/users/littledan","html_url":"https://github.com/littledan","followers_url":"https://api.github.com/users/littledan/followers","following_url":"https://api.github.com/users/littledan/following{/other_user}","gists_url":"https://api.github.com/users/littledan/gists{/gist_id}","starred_url":"https://api.github.com/users/littledan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/littledan/subscriptions","organizations_url":"https://api.github.com/users/littledan/orgs","repos_url":"https://api.github.com/users/littledan/repos","events_url":"https://api.github.com/users/littledan/events{/privacy}","received_events_url":"https://api.github.com/users/littledan/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T21:38:47Z","updated_at":"2016-11-09T21:38:47Z","body":"@DvdGiessen The problem with the `private` keyword like this is that it could only let you refer to the receiver (the current `this` value); you would need a different syntax to access the private field/method on other instances. It's hard for me to picture what that syntax should be, while being analogous."}}
{"actor":{"display_login":"littledan"}}