Changed toJson() to not ignore $ properties

This commit is contained in:
Vojta Jina 2010-11-05 22:37:55 +00:00 committed by Igor Minar
parent c780030c6e
commit fe8353bc5e
2 changed files with 7 additions and 14 deletions

View file

@ -72,7 +72,7 @@ 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 (k.indexOf('$') === 0 || obj[k] === _undefined) if (obj[k] === _undefined)
continue; continue;
keys.push(k); keys.push(k);
} }

View file

@ -49,10 +49,6 @@ describe('json', function(){
expect(fromJson("false")).toBeFalsy(); expect(fromJson("false")).toBeFalsy();
}); });
it('should ignore $$ properties', function() {
expect(toJson({$$:0})).toEqual("{}");
});
it('should serialize array with empty items', function() { it('should serialize array with empty items', function() {
var a = []; var a = [];
a[1] = "X"; a[1] = "X";
@ -77,18 +73,15 @@ describe('json', function(){
expect(angular.toJson(obj)).toEqual('{"a":"b","recursion":RECURSION}'); expect(angular.toJson(obj)).toEqual('{"a":"b","recursion":RECURSION}');
}); });
it('should ignore $ properties', function() { it('should serialize $ properties', function() {
var scope = createScope(); var obj = {$a: 'a'}
scope.a = 'a'; expect(angular.toJson(obj)).toEqual('{"$a":"a"}');
scope['$b'] = '$b';
scope.c = 'c';
expect(angular.toJson(scope)).toEqual('{"a":"a","c":"c","this":RECURSION}');
}); });
it('should serialize inherited properties', function() { it('should serialize inherited properties', function() {
var scope = createScope({p:'p'}); var obj = inherit({p:'p'});
scope.a = 'a'; obj.a = 'a';
expect(angular.toJson(scope)).toEqual('{"a":"a","p":"p","this":RECURSION}'); expect(angular.toJson(obj)).toEqual('{"a":"a","p":"p"}');
}); });
it('should serialize same objects multiple times', function() { it('should serialize same objects multiple times', function() {