Monday, 15 May 2017

JS key rename with defineProperty won't work in Node.js

Object.prototype.prefixKeys = function (prefix) {
 for (var key in this) 
   this.hasOwnProperty(key) 
   && Object.defineProperty(this, prefix + key, {value: this[key]})
   && delete this[key]
}

Code above works as expected in chrome console. But just removes keys in Node v6.10.2. What am I doing wrong?



via Alex Shawnee

No comments:

Post a Comment