3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('dump', function(Y) {
10
* Returns a simple string representation of the object or array.
11
* Other types of objects will be returned unprocessed. Arrays
12
* are expected to be indexed. Use object notation for
15
* If included, the dump method is 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.
32
* @param {Object} o The object to dump.
33
* @param {Number} d How deep to recurse child objects, default 3.
34
* @return {String} the dump result.
37
dump = function(o, d) {
38
var i, len, s = [], type = L.type(o);
40
// Cast non-objects to string
41
// Skip dates because the std toString is what we want
42
// Skip HTMLElement-like objects because trying to dump
43
// an element will cause an unhandled exception in FF 2.x
46
} else if (type == 'date') {
48
} else if (o.nodeType && o.tagName) {
49
return o.tagName + '#' + o.id;
50
} else if (o.document && o.navigator) {
52
} else if (o.location && o.body) {
54
} else if (type == 'function') {
58
// dig into child objects the depth specifed. Default 3
59
d = (L.isNumber(d)) ? d : 3;
62
if (type == 'array') {
64
for (i = 0, len = o.length; i < len; i = i + 1) {
65
if (L.isObject(o[i])) {
66
s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
77
} else if (type == 'regexp') {
79
// objects {k1 => v1, k2 => v2}
83
if (o.hasOwnProperty(i)) {
86
if (L.isObject(o[i])) {
87
s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
93
s.push('Error: ' + e.message);
111
}, '3.4.1' ,{requires:['yui-base']});