1 var comb = exports; 2 3 /** 4 * 5 * Converts an arguments object to an array 6 * @function 7 * @param {Arguments} args the arguments object to convert 8 * @memberOf comb 9 * @returns {Array} array version of the arguments object 10 */ 11 var argsToArray = comb.argsToArray = function(args) { 12 return Array.prototype.slice.call(args); 13 }; 14 15 /** 16 * Determines if obj is a boolean 17 * 18 * @param {Anything} obj the thing to test if it is a boolean 19 * 20 * @returns {Boolean} true if it is a boolean false otherwise 21 */ 22 comb.isBoolean = function(obj) { 23 var undef, type = typeof obj; 24 return obj != undef && type == "boolean" || type == "Boolean"; 25 }; 26 27 /** 28 * Determines if obj is undefined 29 * 30 * @param {Anything} obj the thing to test if it is undefined 31 * @returns {Boolean} true if it is undefined false otherwise 32 */ 33 comb.isUndefined = function(obj) { 34 var undef; 35 return obj !== null && obj === undef; 36 }; 37 38 /** 39 * Determines if obj is undefined or null 40 * 41 * @param {Anything} obj the thing to test if it is undefined or null 42 * @returns {Boolean} true if it is undefined or null false otherwise 43 */ 44 comb.isUndefinedOrNull = function(obj) { 45 return comb.isUndefined(obj) || comb.isNull(obj); 46 } 47 48 /** 49 * Determines if obj is null 50 * 51 * @param {Anything} obj the thing to test if it is null 52 * 53 * @returns {Boolean} true if it is null false otherwise 54 */ 55 comb.isNull = function(obj) { 56 var undef; 57 return obj !== undef && obj == null; 58 }; 59 60 var isInstance = function(obj, clazz) { 61 if (typeof clazz == "function") { 62 return obj instanceof clazz; 63 } else { 64 return false; 65 } 66 }; 67 68 /** 69 * Determines if obj is an instance of a particular class 70 * 71 * @param {Anything} obj the thing to test if it and instnace of a class 72 * @param {Object} Clazz used to determine if the object is an instance of 73 * 74 * @returns {Boolean} true if it is an instance of the clazz false otherwise 75 */ 76 comb.isInstanceOf = function(obj, clazz) { 77 return argsToArray(arguments).slice(1).some(function(c) { 78 return isInstance(obj, c); 79 }); 80 };