forked from GitHub/gf-core
Added dumpObject to gflib.js.
This commit is contained in:
@@ -126,9 +126,38 @@ Linearizer.prototype.linearizeToTerm = function (tree) {
|
|||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
|
||||||
|
/* from Remedial JavaScript by Douglas Crockford, http://javascript.crockford.com/remedial.html */
|
||||||
function isString(a) { return typeof a == 'string'; }
|
function isString(a) { return typeof a == 'string'; }
|
||||||
function isArray(a) { return a && typeof a == 'object' && a.constructor == Array; }
|
function isArray(a) { return a && typeof a == 'object' && a.constructor == Array; }
|
||||||
function isUndefined(a) { return typeof a == 'undefined'; }
|
function isUndefined(a) { return typeof a == 'undefined'; }
|
||||||
|
function isBoolean(a) { return typeof a == 'boolean'; }
|
||||||
|
function isNumber(a) { return typeof a == 'number' && isFinite(a); }
|
||||||
|
|
||||||
|
function dumpObject (obj) {
|
||||||
|
if (isUndefined(obj)) {
|
||||||
|
return "undefined";
|
||||||
|
} else if (isString(obj)) {
|
||||||
|
return '"' + obj.toString() + '"'; // FIXME: escape
|
||||||
|
} else if (isBoolean(obj) || isNumber(obj)) {
|
||||||
|
return obj.toString();
|
||||||
|
} else if (isArray(obj)) {
|
||||||
|
var x = "[";
|
||||||
|
for (var i = 0; i < obj.length; i++) {
|
||||||
|
x += dumpObject(obj[i]);
|
||||||
|
if (i < obj.length-1) {
|
||||||
|
x += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x + "]";
|
||||||
|
} else {
|
||||||
|
var x = "{";
|
||||||
|
for (var y in obj) {
|
||||||
|
x += y + "=" + dumpObject(obj[y]) + ";" ;
|
||||||
|
}
|
||||||
|
return x + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function copy_arguments(args, start) {
|
function copy_arguments(args, start) {
|
||||||
var arr = new Array();
|
var arr = new Array();
|
||||||
|
|||||||
Reference in New Issue
Block a user