mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
toJson should serialize inherited properties, but not any properties that start with $
This commit is contained in:
parent
0d717310fd
commit
125d725e7d
2 changed files with 13 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue