h-kill.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This methods allows the killing of built-in functions,
  2. // so the shim can take over with that implementation
  3. var HLP = (function() {
  4. "use strict";
  5. var kill;
  6. kill = function(_class, methods) {
  7. /*if(!Array.isArray(methods))
  8. return;*/
  9. if(!_class.originals)
  10. _class.originals = {};
  11. for (var i = 0, len = methods.length; i < len; i++) {
  12. var obj = methods[i];
  13. _class.originals[obj] = _class[obj];
  14. delete _class[obj];
  15. if (obj in _class) {
  16. // try something more aggressive since V8 at least
  17. // appears to ignore the delete.
  18. _class[obj] = null;
  19. if (_class[obj]) {
  20. console.log("Couln't overwrite", obj, "of", _class);
  21. }
  22. }
  23. }
  24. };
  25. return { kill: kill };
  26. }());
  27. HLP.kill(Function.prototype, [
  28. 'bind'
  29. ]);
  30. HLP.kill(Array, [
  31. 'isArray'
  32. ]);
  33. HLP.kill(String.prototype, [
  34. "trim"
  35. ]);
  36. HLP.kill(Object, [
  37. 'keys'
  38. ]);
  39. HLP.kill(Number.prototype, [
  40. 'toFixed'
  41. ]);
  42. HLP.kill(Date, [
  43. 'now', 'parse'
  44. ]);
  45. HLP.kill(Date.prototype, [
  46. "toJSON", "toISOString"
  47. ]);
  48. HLP.kill(Array.prototype, [
  49. 'forEach', 'some', 'every',
  50. 'indexOf', 'lastIndexOf',
  51. 'map', 'filter',
  52. 'reduce', 'reduceRight'
  53. ]);