merging mrjjwright's isBoolean, with tests, docs, and credit

This commit is contained in:
Jeremy Ashkenas
2010-02-27 00:03:36 -05:00
parent bd271e4794
commit 9903905175
4 changed files with 16 additions and 3 deletions

1
README
View File

@@ -28,3 +28,4 @@ Many thanks to our contributors:
Jed Schmidt
Noah Sloan
Luke Sutton
John Wright

View File

@@ -162,7 +162,7 @@
<a href="#functions">functions</a>, <a href="#extend">extend</a>, <a href="#clone">clone</a>, <a href="#tap">tap</a>,
<a href="#isEqual">isEqual</a>, <a href="#isEmpty">isEmpty</a>, <a href="#isElement">isElement</a>,
<a href="#isArray">isArray</a>, <a href="#isArguments">isArguments</a>, <a href="#isFunction">isFunction</a>, <a href="#isString">isString</a>,
<a href="#isNumber">isNumber</a>, <a href="#isDate">isDate</a>, <a href="#isRegExp">isRegExp</a>
<a href="#isNumber">isNumber</a>, <a href="#isBoolean">isBoolean</a>, <a href="#isDate">isDate</a>, <a href="#isRegExp">isRegExp</a>
<a href="#isNaN">isNaN</a>, <a href="#isNull">isNull</a>,
<a href="#isUndefined">isUndefined</a>
</span>
@@ -874,6 +874,16 @@ _.isFunction("moe");
<pre>
_.isNumber(8.4 * 5);
=&gt; true
</pre>
<p id="isBoolean">
<b class="header">isBoolean</b><code>_.isBoolean(object)</code>
<br />
Returns <i>true</i> if <b>object</b> is either <i>true</i> or <i>false</i>.
</p>
<pre>
_.isBoolean(null);
=&gt; false
</pre>
<p id="isDate">

View File

@@ -14,7 +14,7 @@ $(document).ready(function() {
var expected = ["all", "any", "bind", "bindAll", "breakLoop", "clone", "compact",
"compose","defer", "delay", "detect", "each", "every", "extend", "filter", "first",
"flatten", "foldl", "foldr", "forEach", "functions", "head", "identity", "include",
"indexOf", "inject", "intersect", "invoke", "isArguments", "isArray", "isDate", "isElement", "isEmpty", "isEqual",
"indexOf", "inject", "intersect", "invoke", "isArguments", "isArray", "isBoolean", "isDate", "isElement", "isEmpty", "isEqual",
"isFunction", "isNaN", "isNull", "isNumber", "isRegExp", "isString", "isUndefined", "keys", "last", "lastIndexOf", "map", "max",
"methods", "min", "mixin", "noConflict", "pluck", "range", "reduce", "reduceRight", "reject", "rest", "select",
"size", "some", "sortBy", "sortedIndex", "tail", "tap", "template", "times", "toArray", "uniq",
@@ -136,6 +136,8 @@ $(document).ready(function() {
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(NaN), 'NaN is not a boolean');
ok(!_.isBoolean(null), 'null is not a boolean');
ok(_.isBoolean(true), 'but true is');
ok(_.isBoolean(false), 'and so is false');
ok(_.isBoolean(iBoolean), 'even from another frame');

View File

@@ -527,7 +527,7 @@
// Is a given value a boolean?
_.isBoolean = function(obj) {
return (toString.call(obj) === '[object Boolean]');
return obj === true || obj === false;
};
// Is a given value a date?