CoreObject#reopenClass()

reopenClasspublic

Defined in packages/ember-runtime/lib/system/core_object.js:717

Augments a constructor's own properties and functions:

MyObject = Ember.Object.extend({
  name: 'an object'
});

MyObject.reopenClass({
  canBuild: false
});

MyObject.canBuild; // false
o = MyObject.create();

In other words, this creates static properties and functions for the class. These are only available on the class and not on any instance of that class.

App.Person = Ember.Object.extend({
  name : "",
  sayHello : function() {
    alert("Hello. My name is " + this.get('name'));
  }
});

App.Person.reopenClass({
  species : "Homo sapiens",
  createPerson: function(newPersonsName){
    return App.Person.create({
      name:newPersonsName
    });
  }
});

var tom = App.Person.create({
  name : "Tom Dale"
});
var yehuda = App.Person.createPerson("Yehuda Katz");

tom.sayHello(); // "Hello. My name is Tom Dale"
yehuda.sayHello(); // "Hello. My name is Yehuda Katz"
alert(App.Person.species); // "Homo sapiens"

Note that species and createPerson are not valid on the tom and yehuda variables. They are only valid on App.Person.

To add functions and properties to instances of a constructor by extending the constructor's prototype see reopen

doc_EmberJs
2016-11-30 16:49:01
Comments
Leave a Comment

Please login to continue.