The first thing I'd do is remove all the useless comments like
// return the Class object which is now ready to be further extended.
return Class;
...
// execute constructor method if present
if (this.construct) this.construct.apply(this, arguments);
...
// store config
config = scope;
and a million more.
The second thing I'd do is stop using tabs for indentation. Use 4-space indentation instead.
In your for-in loops, ALWAYS use a hasOwnProperty call or Douglas Crockford will revoke your JavaScript privileges. For example
for (var i in config)
this[i] = config[i];
needs to become
for (var i in config) {
if (config.hasOwnProperty(i))
this[i] = config[i];
}
or the world will end in 2012, and you really don't want to be responsible for that.
Stuff like
if (complete === true || ...) ...
is redundant.
Here and there there is an inconsistent use of braces, normally you don't use them for one-line statements but occasionally there is stuff like
if (scope instanceof Function) {
target = scope.prototype[name];
}
Sometimes you make useless checks like
if (jQuery !== undefined && jQuery instanceof Function) ...
undefined
isn't an instance of Function
, so you can skip the undefined check.
Oh, and instanceof
should generally be avoided anyway, since objects created in a different window will return false and IIRC there is an IE memory leak with some COM+ objects, so I'd just replace it (and others like it) with if (typeof jQuery === 'function')
.
window.xa = window.$xa = window.XA = new xa();
I'd pick just one of these, three with nearly identical names just pollute the namespace.
So yeah. I haven't really looked into what this does a lot, just browsed the code and picked at obvious things, but it looks kinda promising. Good luck. :-)
If for some reason you need support for Safari 1.3 and IE 5, which don't support hasOwnProperty, this will work reasonably well.
if (typeof Object.prototype.hasOwnProperty !== 'function') {
Object.prototype.hasOwnProperty = function (prop) {
var type = {}.toString.call(this).slice(8, -1);
return this[prop] !== undefined && this[prop] !== window[type].prototype[prop];
};
}