使用JSON.stringify()时,json2.js似乎忽略了父对象的成员.例:
require('./json2.js');
function WorldObject(type) {
this.position = 4;
}
function Actor(val) {
this.someVal = 50;
}
Actor.prototype = new WorldObject();
var a = new Actor(2);
console.log(a.position);
console.log(JSON.stringify(a));
Run Code Online (Sandbox Code Playgroud)
输出是:
4
{"someVal":50}
Run Code Online (Sandbox Code Playgroud)
我希望这个输出:
4
{"position":0, "someVal":50}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的范围变量之一编写规范,但即使它们匹配,它也失败了。
安慰:
Expected [ { id: 1, name: 'Browns', created_at: '2014-08-06T21:38:41.000Z', updated_at: '2014-08-06T21:38:41.000Z' }, { id: 2, name: 'Blues', created_at: '2014-08-06T21:38:53.000Z', updated_at: '2014-08-06T21:38:53.000Z' }, { id: 3, name: 'Greens', created_at: '2014-08-06T21:39:03.000Z', updated_at: '2014-08-06T21:39:03.000Z' } ] to equal [ { id: 1, name: 'Browns', created_at: '2014-08-06T21:38:41.000Z', updated_at: '2014-08-06T21:38:41.000Z' }, { id: 2, name: 'Blues', created_at: '2014-08-06T21:38:53.000Z', updated_at: '2014-08-06T21:38:53.000Z' }, { id: 3, name: 'Greens', created_at: '2014-08-06T21:39:03.000Z', updated_at: '2014-08-06T21:39:03.000Z' } ].
Error: Expected [ { id: 1, name: 'Browns', created_at: '2014-08-06T21:38:41.000Z', updated_at: …
Run Code Online (Sandbox Code Playgroud)