call apply bind
来源:互联网 发布:每天做梦知乎 编辑:程序博客网 时间:2024/05/21 08:46
作用都是改变this的指向
- 在没有参数的情况下
call apply 一样==>call(element) apply(element). - 有参数的情况下
call 参数一次传入 call(element,param1,param2).
apply 参数通过数组传入 apply(element,[param1,param2]). - bind 被动执行 但是bind后边要加()执行
有参数,bind的用法和call一样 但是bind后边要加()执行 bind(element,param1,param2)().- 使用bind其实创建了一个函数 调用就需要在加()执行.
var goudan = { name:"狗蛋", age:18};var ergou = { name:"大狗", age:18, say:function(address,phone){ alert(this.name+"---"+this.age+"---"+phone+"---"+address); }};//ergou.say();//没有参数//ergou.say.call(goudan);//this指向goudan//ergou.say.apply(goudan);//有参数ergou.say.call(goudan,"广州",110);ergou.say.apply(goudan,["广州",110]);ergou.say.bind(goudan,"广州",110)();
bind被动执行
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="Author" content=" "> <title>Document</title> <style type="text/css"> *{margin: 0;padding: 0;} a{text-decoration: none;} ul,li{list-style: none;} body{font-size: 14px;font-family: "微软雅黑";} </style></head><body> <a href="#" id="aa">点我</a> <script type="text/javascript"> /* this */ var aa = document.getElementById("aa"); // var json = { // num:77, // clickMe:function(){ // //1.保存this // var $this = this; // aa.onclick = function(){ // alert($this.num); // } // } // }; var json = { num:77, clickMe:function(){ //保存this aa.onclick = function(){ alert(this.num); }.bind(this);//2 } }; json.clickMe(); //json.clickMe.call(this)//undefined // var a = 1; // document.onclick = function(){ // alert(this.a); // }.bind(window);//当用call(window)就是立即执行,相当于在function(){}(window); </script></body></html>
0 0
- call apply 与 bind
- call()、apply()、bind()
- apply bind call区别
- call,apply,bind
- 【JavaScript】call, apply, bind
- bind apply call异同
- apply call bind区别
- bind , call and apply
- JS call bind apply
- call()、apply()与bind()
- call apply bind
- call()、apply()、bind()详解
- bind apply call
- apply,call,bind
- apply、call、bind
- call,apply,bind
- bind&call&apply
- bind、apply、call解析
- Java Class类用法
- 短信验证码接收平台
- hdu 1342 Lotto(组合数搜索)
- 对输入的字符串调整为首字母大写其余字母小写!
- c++ vector用法
- call apply bind
- Intiall Eclipse PyDev Numpy Scipy Opencv in Window10(64)
- 配置solr的步骤
- A simple network to classify handwritten digits
- 将TensorFlow安装到树莓派中
- SNAT和DNAT的区别
- google帐号的注册方法
- 【Android UI设计与开发】8.顶部标题栏(一)ActionBar
- 第一个MapReduce案例集群模式&本地模式