mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
added _.isBoolean function
This commit is contained in:
@@ -85,6 +85,7 @@ $(document).ready(function() {
|
|||||||
parent.iRegExp = /hi/;\
|
parent.iRegExp = /hi/;\
|
||||||
parent.iNaN = NaN;\
|
parent.iNaN = NaN;\
|
||||||
parent.iNull = null;\
|
parent.iNull = null;\
|
||||||
|
parent.iBoolean = false;\
|
||||||
parent.iUndefined = undefined;\
|
parent.iUndefined = undefined;\
|
||||||
</script>"
|
</script>"
|
||||||
);
|
);
|
||||||
@@ -128,6 +129,18 @@ $(document).ready(function() {
|
|||||||
ok(_.isNumber(iNumber), 'even from another frame');
|
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() {
|
test("objects: isFunction", function() {
|
||||||
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
|
ok(!_.isFunction([1, 2, 3]), 'arrays are not functions');
|
||||||
ok(!_.isFunction('moe'), 'strings are not functions');
|
ok(!_.isFunction('moe'), 'strings are not functions');
|
||||||
|
|||||||
@@ -525,6 +525,11 @@
|
|||||||
return (obj === +obj) || (toString.call(obj) === '[object Number]');
|
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?
|
// Is a given value a date?
|
||||||
_.isDate = function(obj) {
|
_.isDate = function(obj) {
|
||||||
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
|
return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
|
||||||
|
|||||||
Reference in New Issue
Block a user