DNode 'Object.keys not found' error
In a recent project I had to integrate DNode in a node.js application which broacasts realtime events to connnected clients in the browser. For those who wonder what DNode is, its a node.js module which uses socket-io underneath to carry out RPC method calls between your browser and your backend application. More details about DNode can be found here: DNode github
In older browsers such as Firefox 3, it complains that a method called 'Object.keys' is not found. This is caused by the inclusion of 'dnode.js' in the browser script which makes a call to Object.keys.
To fix this I added in an additional piece of javascript from the older branch or version of dnode 0.5 as follows:
if (!Object.keys) Object.keys = function (obj) { var keys = []; for (var key in obj) { if (obj.hasOwnProperty(key)) keys.push(key); } return keys; }; if (typeof Object.create === 'undefined') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; }
Drop the above into an external js file, include it and restart dnode again and provided you are using the latest version of jquery the above should make dnode cross browser compliant.I have tested it on firefox 3 and 7; chrome and safari on the mac.
Due to significant rewrite of the dnode library, this only affects the latest master branch and the npm version. If you are using an older version such as 0.5 the changes above has already been merged in to the core. For more details refer to the git commits and this issue here