网页参数绑定_用绑定绑定参数

网页参数绑定

One of my favorite and most essential Function method is bind, a function we added to MooTools when it wasn't featured in the JavaScript language itself. We often think of using bind to simply bind a method's call to its host object, but did you know you can also bind arguments with the host object?

我最喜欢的也是最基本的Function方法之一是bind ,这是我们在JavaScript语言本身未提供的功能时添加到MooTools的函数。 我们经常想到使用bind来简单地将方法的调用绑定到其宿主对象,但是您知道您也可以将参数与宿主对象绑定吗?

You've probably done something like this:

您可能已经做过这样的事情:


this._onTargetAvailable = this._onTargetAvailable.bind(this);

That pattern is frequently used, especially in classed-based code or when passing callback functions. What you may not often see is bound arguments:

经常使用该模式,尤其是在基于分类的代码中或在传递回调函数时。 您可能不会经常看到的是绑定参数:


this._onTargetAvailable = this._onTargetAvailable.bind(
    this,
    arg1,
    arg2,
    arg3
);

Binding arguments gives you more power in how your bound function is used! Whenever onTargetAvailable is called, the arguments you provide will be in that order, and any additional arguments will be added to the end of the argument list!

绑定参数使您可以更有效地使用绑定函数! 每当onTargetAvailable ,您提供的参数将按照该顺序排列,并且任何其他参数都将添加到参数列表的末尾!

翻译自: https://davidwalsh.name/bind-arguments

网页参数绑定

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值