mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-10 07:44:43 +00:00
fix JSON to match native browser behavior
This commit is contained in:
parent
f57536ddb6
commit
26e651996a
2 changed files with 6 additions and 5 deletions
|
|
@ -128,9 +128,9 @@ function toJsonArray(buf, obj, pretty, stack) {
|
||||||
var childPretty = pretty ? pretty + " " : false;
|
var childPretty = pretty ? pretty + " " : false;
|
||||||
var keys = [];
|
var keys = [];
|
||||||
for(var k in obj) {
|
for(var k in obj) {
|
||||||
if (obj[k] === undefined)
|
if (obj.hasOwnProperty(k) && obj[k] !== undefined) {
|
||||||
continue;
|
keys.push(k);
|
||||||
keys.push(k);
|
}
|
||||||
}
|
}
|
||||||
keys.sort();
|
keys.sort();
|
||||||
for ( var keyIndex = 0; keyIndex < keys.length; keyIndex++) {
|
for ( var keyIndex = 0; keyIndex < keys.length; keyIndex++) {
|
||||||
|
|
|
||||||
|
|
@ -78,10 +78,11 @@ describe('json', function(){
|
||||||
expect(angular.toJson(obj)).toEqual('{"$a":"a"}');
|
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'});
|
var obj = inherit({p:'p'});
|
||||||
obj.a = 'a';
|
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() {
|
it('should serialize same objects multiple times', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue