methods.js 772 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* eslint id-length: 0 */
  2. "use strict";
  3. var d = require("d");
  4. module.exports = function (t, a) {
  5. var value = [], obj = {};
  6. Object.defineProperties(
  7. obj,
  8. t({
  9. someFn: d(
  10. function (x, y) {
  11. a(this, obj);
  12. return x + y;
  13. },
  14. {
  15. refCounter: true,
  16. dispose: function (val) {
  17. value.push(val);
  18. }
  19. }
  20. )
  21. })
  22. );
  23. obj = Object.create(obj);
  24. obj.someFn(3, 7);
  25. obj.someFn(5, 8);
  26. obj.someFn(12, 4);
  27. a.deep(value, [], "Pre");
  28. obj.someFn(5, 8);
  29. obj.someFn.deleteRef(5, 8);
  30. a.deep(value, [], "Pre");
  31. obj.someFn.deleteRef(5, 8);
  32. a.deep(value, [13], "#1");
  33. value = [];
  34. obj.someFn.deleteRef(12, 4);
  35. a.deep(value, [16], "#2");
  36. value = [];
  37. obj.someFn(77, 11);
  38. obj.someFn.clear();
  39. a.deep(value, [10, 88], "Clear all");
  40. };