with Array.prototype.test = undefined; your methods set the value to undefinied and this will not remove it.
If you really want to delete a method (property), use delete Array.prototype.test;
ps But in this case (with the object {} ) → you cannot get what you want with delete .
Array.prototype inherited from Object.prototype , and after removing Array.prototype.test your code will find Object.prototype.test and call it.
I think the best way to do what you want is to do something like this:
Object.defineProperty(Object.prototype, 'test', { enumerable: false, configurable: false, writable: true, value: function(test) { alert('In test' + test); } }); Object.defineProperty(Array.prototype, 'test', { enumerable: false, configurable: false, writable: false, value: function() { throw new Error('You can\'t do it!'); } }); try { var a = []; var keys = ""; for (key in a) { keys += key + ', ';
source share