¶ JSUS: JavaScript UtilS.Copyright(c) 2013 Stefano Balietti MIT Licensed Collection of general purpose javascript functions. JSUS helps! See README.md for extra help. |
(function (exports) {
var JSUS = exports.JSUS = {};
|
¶ JSUS._classesReference to all the extensions |
JSUS._classes = {};
|
¶ JSUS.logReference to standard out, by default Params
txt
string
Text to output
|
JSUS.log = function (txt) {
console.log(txt);
};
|
¶ JSUS.extendExtends JSUS with additional methods and or properties taken from the object passed as first parameter. The first parameter can be an object literal or a function. A reference of the original extending object is stored in JSUS._classes If a second parameter is passed, that will be the target of the extension. Params
additional
object
Text to output
target
object
function
The object to extend
Returns
object
function
target The extended object
@see JSUS.get
|
JSUS.extend = function (additional, target) {
if ('object' !== typeof additional && 'function' !== typeof additional) {
return target;
}
|
If we are extending JSUS, store a reference of the additional object into the hidden JSUS._classes object; |
if ('undefined' === typeof target) {
target = target || this;
if ('function' === typeof additional) {
var name = additional.toString();
name = name.substr('function '.length);
name = name.substr(0, name.indexOf('('));
} |
! must be object |
else {
var name = additional.constructor || additional.__proto__.constructor;
}
if (name) {
this._classes[name] = additional;
}
}
for (var prop in additional) {
if (additional.hasOwnProperty(prop)) {
if (typeof target[prop] !== 'object') {
target[prop] = additional[prop];
} else {
JSUS.extend(additional[prop], target[prop]);
}
}
} |
additional is a class (Function) TODO: this is true also for {} |
if (additional.prototype) {
JSUS.extend(additional.prototype, target.prototype || target);
};
return target;
};
|
¶ JSUS.requireReturns a copy of one / all the objects that have extended the current instance of JSUS. The first parameter is a string representation of the name of the requested extending object. If no parameter is passed a copy of all the extending objects is returned. Params
className
string
The name of the requested JSUS library
Returns
function
boolean
The copy of the JSUS library, or FALSE if the library does not exist
|
JSUS.require = JSUS.get = function (className) {
if ('undefined' === typeof JSUS.clone) {
JSUS.log('JSUS.clone not found. Cannot continue.');
return false;
}
if ('undefined' === typeof className) return JSUS.clone(JSUS._classes);
if ('undefined' === typeof JSUS._classes[className]) {
JSUS.log('Could not find class ' + className);
return false;
}
return JSUS.clone(JSUS._classes[className]); |
return new JSUS._classesclassName; |
}; |
¶ JSUS.isNodeJSReturns TRUE when executed inside Node.JS environment Returns
boolean
TRUE when executed inside Node.JS environment
|
JSUS.isNodeJS = function () {
return 'undefined' !== typeof module
&& 'undefined' !== typeof module.exports
&& 'function' === typeof require;
}; |
¶ Node.JS includesif node |
if (JSUS.isNodeJS()) {
require('./lib/compatibility');
require('./lib/obj');
require('./lib/array');
require('./lib/time');
require('./lib/eval');
require('./lib/dom');
require('./lib/random');
require('./lib/parse');
require('./lib/fs');
} |
end node |
})('undefined' !== typeof module && 'undefined' !== typeof module.exports ? module.exports: window);
|