louischatriot/nedb — pull request #188 by szwacz (2014-06-30 19:34:39+00:00)
Title: Fix for strange Date behavior in Node Webkit

This is fix for https://github.com/louischatriot/nedb/issues/145

The issue was caused by the fact that node-webkit is actually two JS runtimes merged together (node.js and browser), and both of them have its own primitive types. More on this: https://github.com/rogerwang/node-webkit/wiki/Differences-of-JavaScript-contexts

To fix this issue I had to remove references to `Date.prototype`, because this is different object for node context, and for webkit context (the custom `toJSON` for serializing dates applied only in node context). If Date is constructed in webkit context, and then passed to node context it has different prorotype chain.

Fix is a little hackish but safe, since database is not used to store functions, name collision with something what has method `getTime` and is not date at the same time is highly unlikely.