Saturday, 28 September 2013

Are prototypes in node.js different

Are prototypes in node.js different

I have found some differences between prototypes in node.js and the
browser, i have this sample here.
function test() {
this.hello = 'world';
console.log(this);
}
test.prototype.hello = function() {
console.log('something');
}
new test();
Browser output:
test { hello: "world", hello: function }
Node.js output:
{ hello: 'world' }
Now, this is annoying because I wan't to loop through this and wrap
something with the functions, but in node the functions do not show up in
the loop but you can still call them.
Why does this happen, what are the differences between prototypes in node
& the browser?
JSFiddle: http://jsfiddle.net/Q3rQd/1/

No comments:

Post a Comment