Comparing version 0.1.3 to 0.1.4
75
jsus.js
(function (exports) { | ||
/** | ||
* JSUS: JavaScript UtilS. | ||
* Copyright(c) 2012 Stefano Balietti | ||
* MIT Licensed | ||
* | ||
* Collection of general purpose javascript functions. JSUS helps! | ||
* | ||
* JSUS is designed to be modular and easy to extend. | ||
* | ||
* Just use: | ||
* | ||
* JSUS.extend(myClass); | ||
* | ||
* to extend the functionalities of JSUS. All the methods of myClass | ||
* are immediately added to JSUS, and a reference to myClass is stored | ||
* in JSUS._classes. | ||
* | ||
* MyClass can be either of type Object or Function. | ||
* | ||
* JSUS can also extend other objects. Just pass a second parameter: | ||
* | ||
* | ||
* JSUS.extend(myClass, mySecondClass); | ||
* | ||
* and mySecondClass will receive all the methods of myClass. In this case, | ||
* no reference of myClass is stored. | ||
* | ||
* JSUS come shipped in with a default set of libraries: | ||
* | ||
* 1. OBJ | ||
* 2. ARRAY | ||
* 3. TIME | ||
* 4. EVAL | ||
* 5. DOM | ||
* 6. RANDOM | ||
* | ||
* See the their README files for help. | ||
* | ||
*/ | ||
var JSUS = exports.JSUS = {}; | ||
JSUS._classes = {}; | ||
JSUS.extend = function (additional, target) { | ||
if (!additional) return target; | ||
if ('object' !== typeof additional && 'function' !== typeof additional) { | ||
return target; | ||
} | ||
// console.log('A'); | ||
// console.log(additional); | ||
// | ||
// console.log('T'); | ||
// console.log(target); | ||
// | ||
// If we are extending JSUS, store a reference | ||
// of the additional object into the hidden | ||
// JSUS._classes object; | ||
if ('undefined' === typeof target) { | ||
var 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; | ||
} | ||
} | ||
var target = target || this; | ||
for (var prop in additional) { | ||
@@ -33,3 +86,2 @@ if (additional.hasOwnProperty(prop)) { | ||
return target; | ||
@@ -48,3 +100,4 @@ }; | ||
// end node | ||
})('undefined' !== typeof module && 'undefined' !== typeof module.exports ? module.exports: window); | ||
})('undefined' !== typeof module && 'undefined' !== typeof module.exports ? module.exports: window); |
{ | ||
"name": "JSUS", | ||
"description": "JavaScript UtilS. Collection of general purpose functions. JSUS helps!", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"keywords": [ "util", "general", "array", "eval", "time", "date", "object"], | ||
@@ -6,0 +6,0 @@ "author": "Stefano Balietti <futur.dorko@gmail.com>", |
20436
11
665