node-wordnet-magic icon indicating copy to clipboard operation
node-wordnet-magic copied to clipboard

Critical issue: your helper functions for Array and String classes are enumerable!

Open drummerv opened this issue 8 years ago • 0 comments

` // extend prototype objects

// String if (!String.prototype.hasOwnProperty("repeat")){ String.prototype.repeat = function(num){ return new Array( num + 1 ).join( this ); }; }

if (!String.prototype.hasOwnProperty("endsWith")){ String.prototype.endsWith = function(str){ var myRegExp = new RegExp(str + "$"); return myRegExp.test(this); }; }

// Array if (!Array.prototype.hasOwnProperty("pick")){ Array.prototype.pick = function(name){ return this.map(function(elem){ return elem[name]; }); }; }

if (!Array.prototype.hasOwnProperty("contains")){ Array.prototype.contains = function(elem){ for (var q = 0; q < this.length; q++){ if (elem == this[q]) { return true; } } return false; }; } `

Use code below instead to fix the issue.

Object.defineProperty(Array.prototype, "myfunction", { enumerable: false, //to avoid for-in issues! value: function(args){ return args; } });

drummerv avatar Dec 05 '16 08:12 drummerv