Ember inheritance
HTML
<script src="https://github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="https://github.com/downloads/emberjs/ember.js/ember-1.0.pre.js"></script>
JavaScript
var Person = Ember.Object.extend({
species: "homo sapiens",
gender: null,
age: null,
chromosomes: null,
init: function() {
this._super();
this.set("chromosomes", ["x"]);
}
});
var Man = Person.extend({
gender: "male",
init: function() {
this._super();
this.chromosomes.push("y");
}
});
var Woman = Person.extend({
gender: "female",
init: function() {
this._super();
this.chromosomes.push("x");
}
});
var joe = Man.create({
name: "Joe",
age: 25
});
var jane = Woman.create({
name: "Jane",
age: 26
});
console.log(joe.get("name"));
console.log("- species: " + joe.get("species"));
console.log("- gender: " + joe.get("gender"));
console.log("- age: " + joe.get("age"));
console.log("- chromosomes: " + joe.get("chromosomes"));
console.log(jane.get("name"));
console.log("- species: " + jane.get("species"));
console.log("- gender: " + jane.get("gender"));
console.log("- age: " + jane.get("age"));
console.log("- chromosomes: " + jane.get("chromosomes"));