Permalink
Browse files

Docs and 0.1.0 polish

  • Loading branch information...
1 parent e0738ad commit 331b4781e04fa93e88b86e3cbb4f3f1f286c2eb1 Christian Johansen committed Mar 6, 2011
Showing with 118 additions and 3 deletions.
  1. +1 −1 AUTHORS
  2. +1 −1 LICENSE
  3. +115 −0 doc/util.txt
  4. +1 −1 package.json
View
@@ -1,3 +1,3 @@
-Buster.JS Assert was written by
+Buster.JS Utils was written by
August Lilleaas, augustlilleaas@gmail.com
Christian Johansen, christian@cjohansen.no
View
@@ -1,6 +1,6 @@
(The BSD License)
-Copyright (c) 2010, August Lilleaas, augustlilleaas@gmail.com and
+Copyright (c) 2010-2011, August Lilleaas, augustlilleaas@gmail.com and
Christian Johansen, christian@cjohansen.no
All rights reserved.
View
@@ -0,0 +1,115 @@
+Buster Util 0.1.0 documentation
+===============================
+:Author: Christian Johansen
+:Email: christian@cjohansen.no
+:Author: August Lilleaas
+:Email: august.lilleaas@gmail.com
+
+A collection of utilities mostly intended for internal use in Buster.JS.
+
+Table of contents
+-----------------
+* <<buster-util,The buster-util module>>
+
+[[buster-util]]
+The buster-util module
+----------------------
+
+The buster-util module is stable and can be freely used when extending Buster,
+or for any other projects should you wish to do so.
+
++buster.util.isNode(object)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Returns +true+ if the object is a DOM node. The check is made by attempting to
+call +appendChild+ on it, passing in an element.
+
++buster.util.isElement(object)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Returns +true+ if the object is a DOM element. The check is made by calling
++isNode+ and asserting that the element's +nodeType+ is 1 (i.e. element).
+
++buster.util.bind(object, methodOrString)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Binds a function to an object, such that its +this+ value is fixed regardless of
+how it's called. The function works much like +Function.prototype.bind+ - it is
+provided here to work in environments that do not support
++Function.prototype.bind+.
+
+[source,javascript]
+----
+var homer = {
+ name: "Homer",
+
+ burp: function () {
+ return this.name + " goes buuuuuurp";
+ }
+};
+
+var func = buster.util.bind(homer, homer.burp);
+func(); // "Homer goes buuuuuurp"
+
+var func2 = buster.util.bind(home, "burp");
+func2(); // "Homer goes buuuuuurp"
+----
+
++buster.util.isArguments(object)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Returns true if the argument is an +arguments+ object. Buster checks this by
+making sure the object is array-like, but not actually an array.
+
+[source,javascript]
+----
+function check() {
+ buster.util.isArguments(arguments); // true
+}
+
+buster.util.isArguments([]); // false
+----
+
++buster.util.keys(object)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Cross-browser implementation of
+<a
+href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys">Object.keys</a>.
+From MDC: "returns an array whose elements are strings corresponding to the
+enumerable properties found directly upon object. The ordering of the properties
+is the same as that given by looping over the properties of the object
+manually".
+
++buster.util.create(object)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Cross-browser implementation of
+<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create">Object.create</a>
++buster.util.create+ only supports creating a new object with the specified
+object as its prototype. It does not support property descriptors.
+
++buster.util.extend(target, source1, source2, ...)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Extends the target object by copying all the properties of all the sources onto
+it. Sources as processed in order. The method also returns the target object.
+
+[source,javascript]
+----
+var target = { id: 42, num: 0 };
+
+target = buster.util.create(target,
+ { id: 13, name: "One" },
+ { name: "Two", prop: "erty" });
+
+//=> { id: 13, num: 0, name: "Two", prop: "erty" }
+----
+
++buster.util.nextTick(callback)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Calls the callback on the next tick of the event loop. On Node.js this method
+simply delegates to +process.nextTick+. In the browser, +nextTick+ is emulated
+by passing the callback to +setTimeout(callback, 0)+
+
View
@@ -1,5 +1,5 @@
{
"name": "buster-util",
- "version": "0.0.1",
+ "version": "0.1.0",
"main": "./lib/buster-util"
}

0 comments on commit 331b478

Please sign in to comment.