prototype bind 和 bindAsEventListener的区别

<script type="text/JavaScript"> alimama_pid="mm_11307516_1146824_2589042"; alimama_titlecolor="0000FF"; alimama_descolor ="000000"; alimama_bgcolor="FFFFFF"; alimama_bordercolor="E6E6E6"; alimama_linkcolor="008000"; alimama_bottomcolor="FFFFFF"; alimama_anglesize="0"; alimama_bgpic="0"; alimama_icon="0"; alimama_sizecode="12"; alimama_width=468; alimama_height=60; alimama_type=2; </script> <script src="http://a.alimama.cn/inf.js" type="text/javascript"> </script>



prototype.js代码
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

实例代码
function class(aa){
  this.aa = aa;
}
class.prototype.show = function(arg1,arg2){}
class.prototype.close = function(){}

bind可以绑定多个参数

Event.observe(menuItem,this.eventType,this.show.bind(this,arg1,arg2))

bindAsEventListener只可以绑定一个this参数

Event.observe(menuItem,this.eventType,this.show.bindAsEventListener(this))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值