解决function.bind()方法
于是只好再次上网 google 解决方案,功夫不负有心人,我们在 firefox 的开发站找到了解决方案,那就是增加 property 原型使得所有浏览器都能支持 bind 方法,代码如下:
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () { },
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
解决function.bind()方法的更多相关文章
- ES6下的Function.bind方法
在JavaScript的使用中,this的指向问题始终是一个难点.不同的调用方式,会使this指向不同的对象.而使用call,apply,bind等方式,可改变this的指向,完成一些令人惊叹的黑魔法 ...
- IE8支持function.bind()方法
这个 bind 方法仅仅有在 ie10 版本号的浏览器才得到原生支持,低于该版本号的浏览器下运行时会得到一个 undefined 的错误提示.于是仅仅好再次上网 google 解决方式,功夫不负有心人 ...
- Function.bind 方法
this.num = 9; var mymodule = { num: 81, getNum: function() { return this.num; } }; module.getNum(); ...
- 浅析 JavaScript 中的 Function.prototype.bind() 方法
Function.prototype.bind()方法 bind() 方法的主要作用就是将函数绑定至某个对象,bind() 方法会创建一个函数,函数体内this对象的值会被绑定到传入bind() 函数 ...
- prototype.js中Function.prototype.bind方法浅解
prototype.js中的Function.prototype.bind方法: Function.prototype.bind = function() { var __method = this; ...
- react 调用 function 的写法 及 解决 react onClick 方法自动执行
1.react 调用方法的写法 (1)方式一 onClick={this.getFetchData.bind(this,item.id)} (2)方式二 getFetchData(e){ this.s ...
- JavaScript 中的 Function.prototype.bind() 方法
转载自:https://www.cnblogs.com/zztt/p/4122352.html Function.prototype.bind()方法 bind() 方法的主要作用就是将函数绑定至某个 ...
- Javascript中call,apply,bind方法的详解与总结
在 javascript之 this 关键字详解 文章中,谈及了如下内容,做一个简单的回顾: 1.this对象的涵义就是指向当前对象中的属性和方法. 2.this指向的可变性.当在全局作用域时,thi ...
- 如何在JavaScript中正确引用某个方法(bind方法的应用)
在JavaScript中,方法往往涉及到上下文,也就是this,因此往往不能直接引用,就拿最常见的console.log("info…")来说,避免书写冗长的console,直接用 ...
随机推荐
- django获取某一个字段的列表,values/values_list/flat
class Building(models.Model): corporation = models.ForeignKey('company.Corporation', verbose_name=u' ...
- python Post方式发起http请求 使用百度接口地理编码
import os import httplib import json import urllib baiduapi="api.map.baidu.com:80" src=&qu ...
- Bone Collector(ZeroOnebag)
Bone Collector Problem Description Many years ago , in Teddy’s hometown there was a man who was call ...
- c# Parallel并行运算
string str = ""; DataTable dt=new DataTable(); dt.Columns.Add("name", typeof(Sys ...
- Keil C51.uew
/L15"Keil C51" Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char ...
- Android中退出多个Activity的两个经典方法
这里介绍两种方法:一种把每个activity记住,然后逐一干掉:另一种思路是使用广播. 方法一.用list保存activity实例,然后逐一干掉 上代码: import java.util.Linke ...
- selenium webdriver使用过程中出现Element is not currently visible and so may not be interacted with的处理方法
参考文章: http://blog.csdn.net/passionboyxie/article/details/28661107 http://www.spasvo.com/ceshi/open/k ...
- UESTC_基爷的中位数 2015 UESTC Training for Search Algorithm & String<Problem D>
D - 基爷的中位数 Time Limit: 5000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- Linux系统下定时上传文件至FTP服务器脚本
环境:Red Hat Enterprise Linux Server release 6.4 需求:需要将Oracle数据库的定时备份上传至FTP服务器 1.干货,用户名:oracle,数据库名称:X ...
- MFC学习之程序执行过程梳理
*首先利用全局变量对象theApp启动应用程序.这是由于这个全局对象,基类CWinApp中this的指针才干指向这个对象.假设没有这个全局对象,程序在编译时不会出错,但在执行时就会出错. *调用全局应 ...