2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
8
* Returns a simple string representation of the object or array.
9
* Other types of objects will be returned unprocessed. Arrays
10
* are expected to be indexed. Use object notation for
13
* If included, the dump method is added to the YUI instance.
17
YUI.add("dump", function(Y) {
19
var L=Y.Lang, OBJ="{...}", FUN="f(){...}", COMMA=', ', ARROW=' => ',
22
* The following methods are added to the YUI instance
27
* Returns a simple string representation of the object or array.
28
* Other types of objects will be returned unprocessed. Arrays
29
* are expected to be indexed. Use object notation for
32
* @TODO dumping a window is causing an unhandled exception in
35
* This method is in the 'dump' module, which is not bundled with
39
* @param o {object} The object to dump
40
* @param d {int} How deep to recurse child objects, default 3
41
* @return {string} the dump result
43
dump = function(o, d) {
47
// Cast non-objects to string
48
// Skip dates because the std toString is what we want
49
// Skip HTMLElement-like objects because trying to dump
50
// an element will cause an unhandled exception in FF 2.x
53
} else if (o instanceof Date || ("nodeType" in o && "tagName" in o)) {
55
} else if (L.isFunction(o)) {
59
// dig into child objects the depth specifed. Default 3
60
d = (L.isNumber(d)) ? d : 3;
65
for (i=0,len=o.length;i<len;i=i+1) {
66
if (L.isObject(o[i])) {
67
s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);
77
// objects {k1 => v1, k2 => v2}
81
if (Y.Object.owns(o, i)) {
83
if (L.isObject(o[i])) {
84
s.push((d > 0) ? L.dump(o[i], d-1) : OBJ);