Сообщение от eai
|
меня в этой библиотеке подкупил, тот синтаксис который я смогу использовать далее.
|
Синтаксис не важен, важна семантика. А она как раз в подобных библиотеках тщательно скрывается, а вместо неё выпирает несуществующая.
Сообщение от eai
|
а можно пример использования ?
|
function apply(dst) {
for (var i = 1; i < arguments.length; i++) {
for (var prop in arguments[i]) {
if (arguments[i].hasOwnProperty(prop)) {
dst[prop] = arguments[i][prop];
}
}
}
return dst;
}
Function.prototype.inherit = function(proto) {
var that = this;
proto = proto || {};
var constructor = proto.hasOwnProperty('constructor') ? proto.constructor : function() { that.apply(this, arguments); };
var F = function() {};
F.prototype = this.prototype;
constructor.prototype = apply(new F(), proto);
constructor.superclass = this.prototype;
constructor.prototype.constructor = constructor;
return constructor;
};
var A = Object.inherit({
constructor: function(a) {
this.a = a;
},
method: function() {
alert(this.a);
}
});
var B = A.inherit({
constructor: function() {
B.superclass.constructor.apply(this, arguments);
this.a++;
}
});
var a = new A(5);
var b = new B(5);
a.method();
b.method();