underscore.js 802 B

12345678910111213141516171819202122232425262728
  1. var _setup = require('./_setup.js');
  2. // If Underscore is called as a function, it returns a wrapped object that can
  3. // be used OO-style. This wrapper holds altered versions of all functions added
  4. // through `_.mixin`. Wrapped objects may be chained.
  5. function _(obj) {
  6. if (obj instanceof _) return obj;
  7. if (!(this instanceof _)) return new _(obj);
  8. this._wrapped = obj;
  9. }
  10. _.VERSION = _setup.VERSION;
  11. // Extracts the result from a wrapped and chained object.
  12. _.prototype.value = function() {
  13. return this._wrapped;
  14. };
  15. // Provide unwrapping proxies for some methods used in engine operations
  16. // such as arithmetic and JSON stringification.
  17. _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
  18. _.prototype.toString = function() {
  19. return String(this._wrapped);
  20. };
  21. module.exports = _;