Skip to content

Instantly share code, notes, and snippets.

@shadedyin
Last active August 29, 2015 13:58
Show Gist options
  • Save shadedyin/9951657 to your computer and use it in GitHub Desktop.
Save shadedyin/9951657 to your computer and use it in GitHub Desktop.
/** @module Auxiliary */
var toString = Object.prototype.toString;
/**
* Iterates over `args` and invokes the supplied callback with an
* `item` and `index`.
*
* @param {array} args - The array of items to iterate over.
* @param {function} callback - The function to call for each index.
*/
exports.each = function(args, callback) {
var i = -1; while(args[++i]) { callback(args[i], i + 1); };
};
var types = [
'Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'
];
exports.each(types, function(type) {
exports['is' + type] = function(obj) {
return toString.call(obj) === '[object ' + type + ']';
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment