From 5be325a0c1a660268d29541bc668d9cb7d641fcb Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 5 Nov 2010 23:14:44 +0000 Subject: [PATCH] Refactored toJsonArray(), added isBoolean() function --- src/Angular.js | 1 + src/JSON.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 9177853a2b26..dbd662ce6898 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -312,6 +312,7 @@ function isString(value){ return typeof value == $string;} function isNumber(value){ return typeof value == $number;} function isArray(value) { return value instanceof Array; } function isFunction(value){ return typeof value == $function;} +function isBoolean(value) { return typeof value == $boolean;} function isTextNode(node) { return nodeName(node) == '#text'; } function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; } function isElement(node) { diff --git a/src/JSON.js b/src/JSON.js index 50f63decbe84..de718527f6c4 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -1,6 +1,6 @@ var array = [].constructor; -function toJson(obj, pretty){ +function toJson(obj, pretty) { var buf = []; toJsonArray(buf, obj, pretty ? "\n " : _null, []); return buf.join(''); @@ -35,37 +35,36 @@ function toJsonArray(buf, obj, pretty, stack) { } if (includes(stack, obj)) { - buf.push("RECURSION"); + buf.push('RECURSION'); return; } stack.push(obj); } - var type = typeof obj; if (obj === _null) { buf.push($null); } else if (obj instanceof RegExp) { buf.push(angular['String']['quoteUnicode'](obj.toString())); - } else if (type === $function) { + } else if (isFunction(obj)) { return; - } else if (type === $boolean) { + } else if (isBoolean(obj)) { buf.push('' + obj); - } else if (type === $number) { + } else if (isNumber(obj)) { if (isNaN(obj)) { buf.push($null); } else { buf.push('' + obj); } - } else if (type === $string) { + } else if (isString(obj)) { return buf.push(angular['String']['quoteUnicode'](obj)); - } else if (type === $object) { - if (obj instanceof Array) { + } else if (isObject(obj)) { + if (isArray(obj)) { buf.push("["); var len = obj.length; var sep = false; for(var i=0; i