callBind.js 843 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. var bind = require('function-bind');
  3. var GetIntrinsic = require('../GetIntrinsic');
  4. var $apply = GetIntrinsic('%Function.prototype.apply%');
  5. var $call = GetIntrinsic('%Function.prototype.call%');
  6. var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
  7. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  8. if ($defineProperty) {
  9. try {
  10. $defineProperty({}, 'a', { value: 1 });
  11. } catch (e) {
  12. // IE 8 has a broken defineProperty
  13. $defineProperty = null;
  14. }
  15. }
  16. module.exports = function callBind() {
  17. return $reflectApply(bind, $call, arguments);
  18. };
  19. var applyBind = function applyBind() {
  20. return $reflectApply(bind, $apply, arguments);
  21. };
  22. if ($defineProperty) {
  23. $defineProperty(module.exports, 'apply', { value: applyBind });
  24. } else {
  25. module.exports.apply = applyBind;
  26. }