The usage of  bind  is to define a specified scope for called function. Because the key this is easy to refer another objet, experically window, instead of itself. Please pay attention to look at the following example:

  1. //Global variables
  2. window.name="Chromium";
  3.  
  4. var person={
  5. name:"Pin"
  6. }
  7.  
  8. function say()
  9. {
  10. alert("My name is "+this.name+"!");
  11. }
  12.  
  13. say(); //the result is : My name is Chromium!
  14.  
  15. var sayfunction=say.bind(person);
  16.  
  17. sayfunction(); //the result is : My name is Pin!

When the function say assign to a variable sayfunction, the scope of this function has been changed. However, if you use the function of bind  to refer a specified object person, the scope will own the refer object person.

How to use the function of bind的更多相关文章

  1. 【转载】C++ function、bind和lambda表达式

    本篇随笔为转载,原贴地址:C++ function.bind和lambda表达式. 本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lambda表达式, function对象和bind机制 ...

  2. 一起Polyfill系列:Function.prototype.bind的四个阶段

    昨天边参考es5-shim边自己实现Function.prototype.bind,发现有不少以前忽视了的地方,这里就作为一个小总结吧. 一.Function.prototype.bind的作用 其实 ...

  3. 聊聊Function的bind()

    bind顾名思义,绑定. bind()方法会创建一个新函数,当这个新函数被调用时,它的this值是传递给bind()的第一个参数,它的参数是bind()的其他参数和其原本的参数. 上面这个定义最后一句 ...

  4. Function.prototype.bind接口浅析

    本文大部分内容翻译自 MDN内容, 翻译内容经过自己的理解. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Glo ...

  5. C++中str1::function和bind

    在C++的TR1中(TechnologyReport)中包括一个function模板类和bind模板函数,使用它们能够实现类似函数指针的功能,但却却比函数指针更加灵活,特别是函数指向类的非静态成员函数 ...

  6. 【转】C++ function、bind以及lamda表达式

    本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lambda表达式, function对象和bind机制.之所以把这三块放在一起讲,是因为这三块之间有着非常密切的关系,通过对比学习,加深对 ...

  7. JavaScript 函数绑定 Function.prototype.bind

    ECMAScript Edition5 IE9+支持原生,作用为将一个对象的方法绑定到另一个对象上执行. Function.prototype.bind = Function.prototype.bi ...

  8. Function.prototype.bind

    解析Function.prototype.bind 简介 对于一个给定的函数,创造一个绑定对象的新函数,这个函数和之前的函数功能一样,this值是它的第一个参数,其它参数,作为新的函数的给定参数. b ...

  9. 解析Function.prototype.bind

    简介 对于一个给定的函数,创造一个绑定对象的新函数,这个函数和之前的函数功能一样,this值是它的第一个参数,其它参数,作为新的函数的给定参数. bind的作用 bind最直接的作用就是改变this的 ...

  10. 2.cocos2dx 3.2在语法的差异,lambada使用表达式和function和bind使用功能

    1        打开 - 内置T32  Cocos2dx-3.2一个专案 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhb ...

随机推荐

  1. 顺序表的基本方法实现C语言版

    顺序表--------------线性表的第一个儿子 这个儿子的结构体定义: typedef int ElemType;//取别名 typedef struct link{ ElemType * he ...

  2. Python删除一个列表元素的方法

    参考资料: https://www.cnblogs.com/xiaodai0/p/10564956.html https://www.cnblogs.com/huangbiquan/articles/ ...

  3. 【JMeter_10】JMeter逻辑控制器__ForEach控制器<ForEach Controller>

    ForEach控制器<ForEach Controller> 业务逻辑: ForEach控制器一般与用户自定义变量/JDBC结果变量一起使用,可以认为他就是一种遍历型循环,该节点下的脚本内 ...

  4. cb05a_c++_STL优先级队列priority_queue_less_greater

    /*cb05a_c++_STL优先级队列priority_queue自适应容器(容器适配器):不能使用list,list不能使用随机操作最大值优先级队列,//把数据放在队列里面是,最大的始终都是放在最 ...

  5. JavaWEB实现qq邮箱发送验证码——qq1692700664

    // 随机验证码public String achieveCode() { String[] beforeShuffle = new String[] { "2", "3 ...

  6. xshell界面变成半透明的怎么办?

    在工具——选项查看选项卡去掉使窗口透明的前的勾就可以了

  7. sql server 分组查询结合日期模糊查询

    分组查询: https://www.cnblogs.com/netserver/p/4518995.html 日期格式化格式: http://blog.csdn.net/qq_16769857/art ...

  8. 浅谈dfs

    搜索(dfs) 搜索分为bfs与dfs 他们的算法思路都是相同的--穷举 可以说,搜索是万能的,但是复杂度往往是指数级的,往往是穷途末路才用的最后方案 dfs dfs核心操作:回溯+前进 想想你第一次 ...

  9. 二.4vue展示用户数据及用户组操作以及给用户组添加额外字段

    一.用户列表 1.新建(1)views/users/index.vue: <template> <div class="user-list-container"& ...

  10. apache frpClien操作报错解决

    #打开配置文件vim /etc/vsftpd/vsftpd.conf #修改配置100行chroot_local_user=NO