Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

underscore-oop.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define(['./_setup', './underscore', './_chainResult', './each'], function (_setup, underscore, _chainResult, each) {
  2. // Add all mutator `Array` functions to the wrapper.
  3. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  4. var method = _setup.ArrayProto[name];
  5. underscore.prototype[name] = function() {
  6. var obj = this._wrapped;
  7. if (obj != null) {
  8. method.apply(obj, arguments);
  9. if ((name === 'shift' || name === 'splice') && obj.length === 0) {
  10. delete obj[0];
  11. }
  12. }
  13. return _chainResult(this, obj);
  14. };
  15. });
  16. // Add all accessor `Array` functions to the wrapper.
  17. each(['concat', 'join', 'slice'], function(name) {
  18. var method = _setup.ArrayProto[name];
  19. underscore.prototype[name] = function() {
  20. var obj = this._wrapped;
  21. if (obj != null) obj = method.apply(obj, arguments);
  22. return _chainResult(this, obj);
  23. };
  24. });
  25. // Extracts the result from a wrapped and chained object.
  26. underscore.prototype.value = function() {
  27. return this._wrapped;
  28. };
  29. // Provide unwrapping proxies for some methods used in engine operations
  30. // such as arithmetic and JSON stringification.
  31. underscore.prototype.valueOf = underscore.prototype.toJSON = underscore.prototype.value;
  32. underscore.prototype.toString = function() {
  33. return String(this._wrapped);
  34. };
  35. return underscore;
  36. });