Skip to content

Commit

Permalink
Merge pull request jashkenas#654 from FarSeeing/master
Browse files Browse the repository at this point in the history
Simplify some isType methods declaration
  • Loading branch information
jashkenas committed Jun 26, 2012
2 parents 64b8f86 + d76acef commit a642f78
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,33 +826,21 @@
return obj === Object(obj);
};

// Is a given variable an arguments object?
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
_['is' + name] = function(obj) {
return toString.call(obj) == '[object ' + name + ']';
};
});

// Define a fallback version of the method in browsers (ahem, IE), where
// there isn't any inspectable "Arguments" type.
_.isArguments = function(obj) {
return toString.call(obj) == '[object Arguments]';
};
if (!_.isArguments(arguments)) {
_.isArguments = function(obj) {
return !!(obj && _.has(obj, 'callee'));
};
}

// Is a given value a function?
_.isFunction = function(obj) {
return toString.call(obj) == '[object Function]';
};

// Is a given value a string?
_.isString = function(obj) {
return toString.call(obj) == '[object String]';
};

// Is a given value a number?
_.isNumber = function(obj) {
return toString.call(obj) == '[object Number]';
};

// Is a given object a finite number?
_.isFinite = function(obj) {
return _.isNumber(obj) && isFinite(obj);
Expand All @@ -869,16 +857,6 @@
return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
};

// Is a given value a date?
_.isDate = function(obj) {
return toString.call(obj) == '[object Date]';
};

// Is the given value a regular expression?
_.isRegExp = function(obj) {
return toString.call(obj) == '[object RegExp]';
};

// Is a given value equal to null?
_.isNull = function(obj) {
return obj === null;
Expand Down

0 comments on commit a642f78

Please sign in to comment.