Classes
Last updated
Last updated
Meanwhile get supported, visibility rules are just based on a common naming convention where properties and methods get prefixed with the underscore character _
if they are private.
Avoid using properties.
Properties can become handy in some extreme cases like the integration of some legacy library, mock, implementing a runtime type checking decorator or something fancy like that etc...
Otherwise, properties will only introduce ambiguity.
Who would imagine that this code might trigger a runtime exception?
Or even worse, things might end up like this:
This is inheritance:
Now, avoid it...
... and prefer composition!
Meanwhile we get the class fields in JavaScript, it is recommended to initialize all the attributes in the constructor. Otherwise, it's hard to figure out which attributes are available on a class. In addition to this, the available attributes will depend on the methods that have been called.