diff options
| author | Misko Hevery | 2011-03-30 16:28:28 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-06-08 13:49:11 -0700 |
| commit | 26e651996a9cd7fa1acf6380fad8b335b769554d (patch) | |
| tree | 38eb40cade86f218b8995000e89d5d9d9124e11d | |
| parent | f57536ddb693f4d610952ed34bad2650f5b1b75c (diff) | |
| download | angular.js-26e651996a9cd7fa1acf6380fad8b335b769554d.tar.bz2 | |
fix JSON to match native browser behavior
| -rw-r--r-- | src/JSON.js | 6 | ||||
| -rw-r--r-- | test/JsonSpec.js | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/JSON.js b/src/JSON.js index 3d329aa5..186bdb1c 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -128,9 +128,9 @@ function toJsonArray(buf, obj, pretty, stack) { var childPretty = pretty ? pretty + " " : false; var keys = []; for(var k in obj) { - if (obj[k] === undefined) - continue; - keys.push(k); + if (obj.hasOwnProperty(k) && obj[k] !== undefined) { + keys.push(k); + } } keys.sort(); for ( var keyIndex = 0; keyIndex < keys.length; keyIndex++) { diff --git a/test/JsonSpec.js b/test/JsonSpec.js index 2067d88f..3b81a44f 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -78,10 +78,11 @@ describe('json', function(){ expect(angular.toJson(obj)).toEqual('{"$a":"a"}'); }); - it('should serialize inherited properties', function() { + it('should NOT serialize inherited properties', function() { + // This is what native Browser does var obj = inherit({p:'p'}); obj.a = 'a'; - expect(angular.toJson(obj)).toEqual('{"a":"a","p":"p"}'); + expect(angular.toJson(obj)).toEqual('{"a":"a"}'); }); it('should serialize same objects multiple times', function() { |
