createBoundESNamespace.js 521 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var bind = require('function-bind');
  3. var OwnPropertyKeys = require('../../helpers/OwnPropertyKeys');
  4. module.exports = function createBoundESNamespace(ES) {
  5. var keys = OwnPropertyKeys(ES);
  6. var result = {};
  7. for (var i = 0; i < keys.length; i++) {
  8. var key = keys[i];
  9. var prop = ES[key];
  10. if (typeof prop === 'function') {
  11. prop = bind.call(prop, undefined);
  12. } else if (prop && typeof prop === 'object') {
  13. prop = createBoundESNamespace(prop);
  14. }
  15. result[key] = prop;
  16. }
  17. return result;
  18. };