diff --git a/.gitignore b/.gitignore index 08d7879..00ce13c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ node_modules browser-version/src browser-version/node_modules + +*.swp +*~ diff --git a/lib/model.js b/lib/model.js index 5bbf1f7..18a8023 100644 --- a/lib/model.js +++ b/lib/model.js @@ -72,8 +72,7 @@ function serialize (obj) { if (v === null) { return null; } // Hackish way of checking if object is Date (this way it works between execution contexts in node-webkit). - // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), - // fortunately "this" is bound here to object which is owner of the key. + // We can't use value directly because for dates it is already string in this function (date.toJSON was already called), so we use this if (typeof this[k].getTime === 'function') { return { $$date: this[k].getTime() }; } return v; diff --git a/test/model.test.js b/test/model.test.js index 499bbdf..d1057b8 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -82,6 +82,7 @@ describe('Model', function () { b = model.serialize(a); c = model.deserialize(b); b.indexOf('\n').should.equal(-1); + b.should.equal('{"test":{"$$date":' + d.getTime() + '}}'); util.isDate(c.test).should.equal(true); c.test.getTime().should.equal(d.getTime()); });