slight class refactoring
This commit is contained in:
parent
34305dabe0
commit
763b01ef08
@ -4,13 +4,36 @@
|
||||
|
||||
L.Class = function() {};
|
||||
|
||||
//Thanks to John Resig and Dean Edwards for inspiration
|
||||
L.Class.extend = function(props) {
|
||||
var _super = this.prototype, statics;
|
||||
|
||||
// extended class with the new prototype
|
||||
function NewClass() {
|
||||
if (!L.Class._prototyping && this.initialize) {
|
||||
this.initialize.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// instantiate class without calling constructor
|
||||
L.Class._prototyping = true;
|
||||
var proto = new this();
|
||||
L.Class._prototyping = false;
|
||||
|
||||
proto.constructor = NewClass;
|
||||
NewClass.prototype = proto;
|
||||
|
||||
// add callParent method
|
||||
if (this != L.Class) {
|
||||
var _super = this.prototype;
|
||||
proto.callParent = function(fnName) {
|
||||
_super[fnName].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
};
|
||||
}
|
||||
|
||||
// mix static properties into the class
|
||||
if (props.statics) {
|
||||
L.Util.extend(NewClass, props.statics);
|
||||
delete props.statics;
|
||||
}
|
||||
|
||||
// mix includes into the prototype
|
||||
if (props.includes) {
|
||||
@ -18,31 +41,10 @@ L.Class.extend = function(props) {
|
||||
delete props.includes;
|
||||
}
|
||||
|
||||
// callParent method
|
||||
if (this != L.Class) {
|
||||
proto.callParent = function(fnName) {
|
||||
_super[fnName].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
};
|
||||
}
|
||||
|
||||
// save static properties
|
||||
if (props.statics) {
|
||||
statics = props.statics;
|
||||
delete props.statics;
|
||||
}
|
||||
|
||||
// mix given properties into the prototype
|
||||
L.Util.extend(proto, props);
|
||||
|
||||
// extended class with the new prototype
|
||||
function NewClass() {
|
||||
if (!L.Class._prototyping && this.initialize) {
|
||||
this.initialize.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
proto.constructor = NewClass;
|
||||
NewClass.prototype = proto;
|
||||
|
||||
// allow inheriting further
|
||||
NewClass.extend = arguments.callee;
|
||||
|
||||
// method for adding properties to prototype
|
||||
@ -50,11 +52,6 @@ L.Class.extend = function(props) {
|
||||
L.Util.extend(this.prototype, props);
|
||||
};
|
||||
|
||||
// mix static properties into the class
|
||||
if (statics) {
|
||||
L.Util.extend(NewClass, statics);
|
||||
}
|
||||
|
||||
//inherit parent's statics
|
||||
for (var i in this) {
|
||||
if (this.hasOwnProperty(i) && i != 'prototype') {
|
||||
|
Loading…
Reference in New Issue
Block a user