Added some environment code and Class implementation

This commit is contained in:
mourner 2010-09-02 13:40:34 +03:00
parent eb5b7d706b
commit 3f2a02c059
2 changed files with 68 additions and 0 deletions

7
src/env.js Normal file
View File

@ -0,0 +1,7 @@
var originalL = L,
L = {};
L.noConflict = function() {
window.L = originalL;
return this;
};

61
src/util/Class.js Normal file
View File

@ -0,0 +1,61 @@
/*
* Class powers the OOP facilities of the library.
*/
L.Class = function() {};
L.Class.extend = function(props) {
var _super = this.prototype, statics;
// instantiate class without calling constructor
L.Class._prototyping = true;
var proto = new this();
L.Class._prototyping = false;
// mix includes into the prototype
if (props.includes) {
L.Util.extend.apply(null, [proto].concat(props.includes));
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;
NewClass.extend = arguments.callee;
// method for adding properties to prototype
NewClass.include = function(props) {
L.Util.extend(this.prototype, props);
};
// mix static properties into the class
if (statics) {
NewClass.include(statics);
}
//TODO inherit parent's statics?
return NewClass;
};