没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > inheritance |
inheritance
|
0 | 0 | 10 |
贡献者 | 讨论 | 代码提交 |
Inheritance.jsInheritance.js is a plugin for the Prototype Javascript library that provides developers with a complete, unobtrusive, Ruby inspired, classical inheritance model. Using Inheritance.js, developers are given the power to easily define classes, sub-classes, and mix-ins, with a sprinkle of syntax sugar. The process of overriding methods is simplified; Inheritance.js uses a properly scoped parent method that is made available only inside an overriding method. To top it off, Inheritance.js accomplishes all this without adding any additional properties or methods to the developer's instantiated objects.
Person = Class.extend({
// adding a mixin
include: Sortable,
// initializer function
initialize: function(name) {
this.name = name;
},
// ... methods ...
toString: function() {
return this.name;
}
});
Employee = Class.extend(Person, {
// adding mixins
include: [Sortable, OtherModule],
// initializer function
initialize: function(name, dept) {
// call parent function
this.parent(name);
// more initialization
this.dept = dept;
},
// ... methods ...
toString: function() {
// call parent function
return this.parent() + ' works in ' + this.dept;
}
});