Create a Person class
Person = Ember.Object.extend ({ function (thing) { alert (thing);}});
Create a person object that is an instance of the person class
var person = person.create ();p Erson.say ("Hello//Alerts" Hello "
When you create an instance, you can also add additional properties to the instance by passing in the object
var tom = person.create ({name: " tom dalehelloworld: function () {this.say ( "hi my name is " + this.get ( ' name //alerts "Hi My name is Tom Dale"
When you create a new instance of an object, you can also override any properties and methods defined in the class
var yehuda = Person.create ({name: "yehuda katz" say: function (thing) {var name = this.get (namethis._super (name + Says: ; // You can use the object's _super
method (which super
is a reserved word in JavaScript) to invoke the original method that you overwrite
} });
< Span class= "local-variable" > < Span class= "delimiter" > you can also use the extend
method to create subclasses of classes. In fact, when we created the new class using the extend
method of the Ember.object
object above, the subclass of
Ember.object was created .
/span>
var Loudperson = person.extend ({ function (thing) { this._super (Thing.touppercase ()); }});
Emberjs Creating a Class