Flow: Private methods on classes

Created on 24 Feb 2015  路  7Comments  路  Source: facebook/flow

TypeScript has a private modifier, which prevents code outside a class from accessing particular properties and methods. Something similar could be done in Flow.

feature request

Most helpful comment

Flow also has own private fields with munge_underscores option.

class A {
  _myPrivateMethod() {}
}

Also native private fields are partially implemented and will be ready soon.

This probably can be closed.
/cc @vkurchatkin

All 7 comments

The modifier is also a shortcut (sugar), as is the public modifier.

constructor( public x : string ) {}
// vs
constructor(x : string) { this.x = x; }

Flow also has own private fields with munge_underscores option.

class A {
  _myPrivateMethod() {}
}

Also native private fields are partially implemented and will be ready soon.

This probably can be closed.
/cc @vkurchatkin

@vjpr flow already has partial support for private (#) properties.

@TrySound Does this include methods?

No, I misread that it's about methods.

Is there a way to designate private constructors? I have a class which should only be created via a static factory method.

Was this page helpful?
0 / 5 - 0 ratings