added _.isBoolean function

This commit is contained in:
John Wright
2010-02-26 21:46:58 -07:00
parent d1ccc1e841
commit bd271e4794
2 changed files with 18 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ $(document).ready(function() {
parent.iRegExp = /hi/;\
parent.iNaN = NaN;\
parent.iNull = null;\
parent.iBoolean = false;\
parent.iUndefined = undefined;\
</script>"
);
@@ -128,6 +129,18 @@ $(document).ready(function() {
ok(_.isNumber(iNumber), 'even from another frame');
});
test("objects: isBoolean", function() {
ok(!_.isBoolean(2), 'a number is not a boolean');
ok(!_.isBoolean("string"), 'a string is not a boolean');
ok(!_.isBoolean("false"), 'the string "false" is not a boolean');
ok(!_.isBoolean("true"), 'the string "true" is not a boolean');
ok(!_.isBoolean(arguments), 'the arguments object is not a boolean');
ok(!_.isBoolean(undefined), 'undefined is not a boolean');
ok(_.isBoolean(true), 'but true is');
ok(_.isBoolean(false), 'and so is false');
ok(_.isBoolean(iBoolean), 'even from another frame');
});
test("objects: isFunction", function() {
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
ok(!_.isFunction('moe'), 'strings are not functions');

View File

@@ -525,6 +525,11 @@
return (obj === +obj) || (toString.call(obj) === '[object Number]');
};
// Is a given value a boolean?
_.isBoolean = function(obj) {
return (toString.call(obj) === '[object Boolean]');
};
// Is a given value a date?
_.isDate = function(obj) {
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);