es5.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (function () {
  2. Object.create = Object.create || function (o) {
  3. if (arguments.length > 1) {
  4. throw new Error('Object.create implementation only accepts the first parameter.');
  5. }
  6. function F() {
  7. }
  8. F.prototype = o;
  9. return new F();
  10. };
  11. Object.getPrototypeOf = Object.getPrototypeOf || function (object) {
  12. return object.proto || object.constructor.prototype;
  13. };
  14. Function.prototype.bind = Function.prototype.bind || function (oThis) {
  15. if (typeof this !== 'function') {
  16. // closest thing possible to the ECMAScript 5 internal IsCallable function
  17. throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
  18. }
  19. var aArgs = Array.prototype.slice.call(arguments, 1),
  20. fToBind = this,
  21. FNOP = function () {
  22. },
  23. fBound = function () {
  24. return fToBind.apply(this instanceof FNOP && oThis ? this : oThis,
  25. aArgs.concat(Array.prototype.slice.call(arguments)));
  26. };
  27. FNOP.prototype = this.prototype;
  28. fBound.prototype = new FNOP();
  29. return fBound;
  30. };
  31. })();