Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4838

Naming convention for private/protected properties and methods

$
0
0

@ondrejsevcik wrote:

Hello,

I couldn’t find any information about naming convention in Ember world for private/protected properties and methods.

export default Component {
  // Attributes passed into component
  firstName: null,
  lastName: null,

  // Private stuff...
  fullName: computed('firstName', 'lastName', function () {
    return get(this, 'firstName') + " " + get(this, 'lastName');
  }),
}

The problem here is that consumer could easily overwrite fullName with his own value without even noticing that it’s intended to be private only.

What’s the convention in Ember world to let my fellow colleagues know that this property is private or protected and it shouldn’t be set from outside?

I can think of a few

  • call readOnly() on computed property -> will throw an error (not applicable to all private stuff as no all private stuff is computed property)
  • use underscore _fullName -> which means I have to use underscore in template, but I guess that’s not a problem
  • use comment with @private attribute -> very easy to overlook

Do you have different naming convention for private and protected properties/methods?

Thank you

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4838

Trending Articles