$.export.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var global = require('./$.global')
  2. , core = require('./$.core')
  3. , hide = require('./$.hide')
  4. , redefine = require('./$.redefine')
  5. , ctx = require('./$.ctx')
  6. , PROTOTYPE = 'prototype';
  7. var $export = function(type, name, source){
  8. var IS_FORCED = type & $export.F
  9. , IS_GLOBAL = type & $export.G
  10. , IS_STATIC = type & $export.S
  11. , IS_PROTO = type & $export.P
  12. , IS_BIND = type & $export.B
  13. , target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]
  14. , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})
  15. , expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {})
  16. , key, own, out, exp;
  17. if(IS_GLOBAL)source = name;
  18. for(key in source){
  19. // contains in native
  20. own = !IS_FORCED && target && key in target;
  21. // export native or passed
  22. out = (own ? target : source)[key];
  23. // bind timers to global for call from export context
  24. exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
  25. // extend global
  26. if(target && !own)redefine(target, key, out);
  27. // export
  28. if(exports[key] != out)hide(exports, key, exp);
  29. if(IS_PROTO && expProto[key] != out)expProto[key] = out;
  30. }
  31. };
  32. global.core = core;
  33. // type bitmap
  34. $export.F = 1; // forced
  35. $export.G = 2; // global
  36. $export.S = 4; // static
  37. $export.P = 8; // proto
  38. $export.B = 16; // bind
  39. $export.W = 32; // wrap
  40. module.exports = $export;