Re: EcmaScript Proposal – Private methods and fields proposals.

Dan Peddle dan at flarework.com
Tue Apr 17 06:48:34 UTC 2018


imagine you are shipping a module for use by others, and you don't want to expose internals to consumers. private methods and properties help to know that only the public API is in use, giving confidence in publishing updates or fixes.

another use case is knowing that naughty developers aren't reaching into your module and changing its behaviour.

I'm sure there's more, but those are the ones that come to mind. 

> On 17. Apr 2018, at 08:17, kai zhu <kaizhu256 at gmail.com> wrote:
> 
> as a javascript web-developer, can someone educate me on how private
> class methods/fields would make one's life easier (rather than harder)
> in getting web-projects shipped?
> 
> ```
> /*
> * how is this cited example better than using a plain object in a web-project?
> * can someone give actual common problems in
> * debugging/integrating/shipping web-projects,
> * that private methods/fields could help simplify (rather than complicate)?
> */
> class HashTable {
>  constructor() {
>    private[Symbol.for('length')] = 0
>  }
>  set(key, value) {
>    private[key] = value
>  }
>  get(key) {
>    return private[key]
>  }
> }
> ```
> 


More information about the es-discuss mailing list