Sunday, 9 April 2017

Set method in node

I'm writting a small library in node and i have found some interesting behavior. When i try these code on cmd:

Object.prototype.set = function (a) { this.a = a };
let obj = {};
obj.set(6);
obj

It returns: { a: [Setter] }

I try to type obj.a and then it returns correctly 6. When i check it on browser it still runs normally without any problem:

Object.prototype.set = function (a) { this.a = a };
let obj = {};
obj.set(6);
obj
// => { a: 6 }

So i wonder what has happened with node. Is this some kind of side effect? Should i care about it and should i put these code into my library? Thanks!

P/s: I'm using node version 7.7.3



via Clite Tailor

No comments:

Post a Comment