yandex / mapsapi-codestyle

JavaScript and TypeScript Style Guide
Other
213 stars 36 forks source link

Class properties order #84

Closed ikokostya closed 6 years ago

ikokostya commented 7 years ago

General

In this issue I want to discuss about fields order in a class declaration.

Public, private, and protected modifiers

Because most code users or readers are first interested in the public interface, not in the implementation details, make sense use the following order: public, protected, private. But there are some drawbacks:

Static and non-static

Should static fields be placed before or after non-static fields?

dmikis commented 7 years ago

Order

public props;
constructor;
public methods;
protected props;
protected methods;
private props;
private methods;

seems to work OK for us. However, we don't use short field declarations.

ikokostya commented 7 years ago

@dmikis Where is a place of private constructor and static properties?

dmikis commented 7 years ago

Private constructor is between private props and methods, analogous to a public one.

Static props are always after non-static ones within access qualifier. I.e. public instance props, public static props, protected instance props, protected static props, etc.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.