How to use the function of bind
2024-09-24 10:59:16
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:
//Global variables
window.name="Chromium"; var person={
name:"Pin"
} function say()
{
alert("My name is "+this.name+"!");
} say(); //the result is : My name is Chromium! var sayfunction=say.bind(person); 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.
最新文章
- NPOI导出Excel合并表头写入公式
- xp下安装jdk8
- 手机WebAPP设计注意事项和解决方法
- leetcode Linked List Cycle
- 【BZOJ-1406】密码箱 约数 + 乱搞 + set?
- GPU优化方法[转]
- android依赖工程,子工程覆盖父工程的相同属性
- FusionCharts(v3.6.0)使用(1)
- js中的referrer使用,返回上一页
- jQuery ajax在GBK编码下表单提交终极解决方案(非二次编码方法)(转)
- Delphi Windows API判断文件共享锁定状态(使用OpenFile来判断)
- win7兼容oracle
- windows 下编译php扩展库pecl里的扩展memcache
- Struts2 设置global timer
- 跟我一起写Makefile(转)
- MIUI10系统怎么样刷成开发版获得ROOT权限
- linux中centros6.7安装php5.6,httpd-2.2.19(web产品化)遇到的问题总结
- 企业环境下的OpenStack自动化功能测试(转载)
- 8-06. 畅通project之局部最小花费问题(35)(最小生成树_Prim)(ZJU_PAT)
- html5-css渐变应用小实例,按钮
热门文章
- Tournament Chart【模拟+vector+map+string】
- 在Unix系统中执行可执行文件
- cb11a_c++_顺序容器的操作4_容器大小操作_resize-max_size
- python 2 与python 3区别汇总
- 前端笔记(关于解决打包时报node-sass错误的问题)
- egret的WebView实现
- POJ 3463 Sightseeing 【最短路与次短路】
- Spring Security(一) —— Architecture Overview
- 2020年Web前端开发工程师市场怎么样?学会什么技术才能拿到高薪
- lambda表达式与函数式(FunctionalInterface)接口