Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

has.js 900B

12345678910111213141516171819202122232425262728293031
  1. var inspect = require('../');
  2. var test = require('tape');
  3. var withoutProperty = function (object, property, fn) {
  4. var original;
  5. if (Object.getOwnPropertyDescriptor) {
  6. original = Object.getOwnPropertyDescriptor(object, property);
  7. } else {
  8. original = object[property];
  9. }
  10. delete object[property];
  11. try {
  12. fn();
  13. } finally {
  14. if (Object.getOwnPropertyDescriptor) {
  15. Object.defineProperty(object, property, original);
  16. } else {
  17. object[property] = original;
  18. }
  19. }
  20. };
  21. test('when Object#hasOwnProperty is deleted', function (t) {
  22. t.plan(1);
  23. var arr = [1, , 3];
  24. Array.prototype[1] = 2; // this is needed to account for "in" vs "hasOwnProperty"
  25. withoutProperty(Object.prototype, 'hasOwnProperty', function () {
  26. t.equal(inspect(arr), '[ 1, , 3 ]');
  27. });
  28. delete Array.prototype[1];
  29. });