Astronomy: difference between class.inherit and class.extend


#1

Just reading the Astronomy package doc, I am a bit confused by the presence of distinct class inheritance

C2 = C1.inherit

and class extensions mechanisms

C1.extend( additional fields )

Couldn’t the extension example:

if (Meteor.isServer) {
  User.extend({
    fields: {
      private: String
    }
  });
}

be handled by an inheritance:

PrivateUser = User.inherit({
  name: 'PrivateUser',
  fields: {
    private: String
   }
});

and then use PrivateUser in the server instead of User?


#2

With extend you change the existing class, by adding a method or a field. The user Class will remain a user class.

If you inherit, you create a new sub-class, that has the properties of he original class, plus whatever you add.

Which one you use depends on what you need. If you need a helper only on server side for example, you can extend it on the server side. If you want to have multiple “types” of something, like an AdminUser and a RegularUser, you’d want to inherit.