Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

31 строка
1.1 KiB

  1. // Android 2.3 上支持的 Function.prototype.bind() 的填充代码
  2. (function () {
  3. if (!Function.prototype.bind) {
  4. Function.prototype.bind = function (thisValue) {
  5. if (typeof this !== "function") {
  6. throw new TypeError(this + " cannot be bound as it is not a function");
  7. }
  8. // bind() 还允许预挂起调用的参数
  9. var preArgs = Array.prototype.slice.call(arguments, 1);
  10. //要对其绑定“this”值和参数的实际函数
  11. var functionToBind = this;
  12. var noOpFunction = function () { };
  13. // 要使用的“this”参数
  14. var thisArg = this instanceof noOpFunction && thisValue ? this : thisValue;
  15. // 产生的绑定函数
  16. var boundFunction = function () {
  17. return functionToBind.apply(thisArg, preArgs.concat(Array.prototype.slice.call(arguments)));
  18. };
  19. noOpFunction.prototype = this.prototype;
  20. boundFunction.prototype = new noOpFunction();
  21. return boundFunction;
  22. };
  23. }
  24. }());