1
0
forked from GitHub/gf-core

Added dumpObject to gflib.js.

This commit is contained in:
bringert
2006-12-15 21:00:21 +00:00
parent 9e559bb7d5
commit 35c4302e48

View File

@@ -126,9 +126,38 @@ Linearizer.prototype.linearizeToTerm = function (tree) {
/* Utilities */
/* from Remedial JavaScript by Douglas Crockford, http://javascript.crockford.com/remedial.html */
function isString(a) { return typeof a == 'string'; }
function isArray(a) { return a && typeof a == 'object' && a.constructor == Array; }
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) {
var arr = new Array();