手贱,写个call玩玩.
2014-03-06 17:05
267 查看
今天在睡觉醒时,突然感觉对call和apply有了点理解,但是又不好表达出来.就随便写几个例子.
call形式:say.call(obj,args);
理解:正常执行say()方法,say()方法中的this指向obj实例.args是传入到say()中的参数,不过这里没有用.
function say() { return this.role; } function Father() { this.role = "爸爸"; } function Mother() { this.role = "妈妈"; } function Brother() { this.role = "兄弟"; } alert(say.call(new Father()));//爸爸 alert(say.call(new Mother()));//妈妈 alert(say.call(new Brother()));//兄弟 alert(say.call(null)); //undefind alert(say.call(window)); //undefind
call形式:say.call(obj,args);
理解:正常执行say()方法,say()方法中的this指向obj实例.args是传入到say()中的参数,不过这里没有用.
相关文章推荐
- 编程实现表示循环小数,例如将1/3表示为0.3(3)就是将循环节放在括号中
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
- Android keystore 证书文件制作
- Tomcat虚拟目录设置
- ExtJS布局(转)
- 吐槽JDK中LinkedList的indexOf方法实现
- Nginx https 搭建
- 面试--常见算法题目
- dicom 查找表
- Ubuntu 命令大全
- 基于安卓4.4的socket通信——文字聊天
- 2014年七个最明显的web设计趋势及其生存技巧
- ORACLE触发器判断是否更新了某个字段
- ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统
- 游戏服务器之角色消息列表
- AngularJS:何时应该使用Directive、Controller、Service?
- 软件开发步骤(基础)
- oracle 索引类型
- 老毛桃一键还原软件超强发布
- 【C语言】20-static和extern关键字2-对变量的作用