diff options
| author | Igor Minar | 2010-09-21 16:19:07 +0200 |
|---|---|---|
| committer | Igor Minar | 2010-09-21 16:27:47 +0200 |
| commit | 125d725e7dcd76b838925ac997b35afad4266752 (patch) | |
| tree | 325f5271b0ccd33494558889e7da2a0225b7007c | |
| parent | 0d717310fd307cfc192b87f5d825c2963db25fa1 (diff) | |
| download | angular.js-125d725e7dcd76b838925ac997b35afad4266752.tar.bz2 | |
toJson should serialize inherited properties, but not any properties that start with $
| -rw-r--r-- | src/JSON.js | 2 | ||||
| -rw-r--r-- | test/JsonTest.js | 17 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/JSON.js b/src/JSON.js index 9fb325ef..4b1326b2 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -70,7 +70,7 @@ function toJsonArray(buf, obj, pretty, stack){ var childPretty = pretty ? pretty + " " : false; var keys = []; for(var k in obj) { - if (!obj.hasOwnProperty(k) || k.indexOf('$$') === 0 || obj[k] === _undefined) + if (k.indexOf('$') === 0 || obj[k] === _undefined) continue; keys.push(k); } diff --git a/test/JsonTest.js b/test/JsonTest.js index f6da26b5..c723121f 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -74,11 +74,18 @@ JsonTest.prototype.testItShouldPreventRecursion = function () { assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj)); }; -JsonTest.prototype.testItShouldSerializeOnlyOwnProperties = function() { - var parent = createScope(); - var child = createScope(parent); - child.c = 'c'; - expect(angular.toJson(child)).toEqual('{"c":"c"}'); +JsonTest.prototype.testItShouldIgnore$Properties = function() { + var scope = createScope(); + scope.a = 'a'; + scope['$b'] = '$b'; + scope.c = 'c'; + expect(angular.toJson(scope)).toEqual('{"a":"a","c":"c","this":RECURSION}'); +}; + +JsonTest.prototype.testItShouldSerializeInheritedProperties = function() { + var scope = createScope({p:'p'}); + scope.a = 'a'; + expect(angular.toJson(scope)).toEqual('{"a":"a","p":"p","this":RECURSION}'); }; JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () { |
