function A(a,b){
this.a=a;
this.b=b
}
var a = A.bind({x:1},1)
var b = new a(2) // {a: 1, b: 2}
加上上一篇文章中说的情况,我们可以总结到,当我们对一个bind返回的函数进行操作时,实际上这种操作是对目标函数的操作,也就是调用bind的函数。下面我们看一下es5文档的说明。
When the [[Construct]] internal method of a function object, F that was created using the bind function is called with a list of arguments ExtraArgs, the following steps are taken:
Let target be the value of F’s [[TargetFunction]] internal property.
If target has no [[Construct]] internal method, a TypeError exception is thrown.
Let boundArgs be the value of F’s [[BoundArgs]] internal property.
Let args be a new list containing the same values as the list boundArgs in the same order followed by the same values as the list ExtraArgs in the same order.
Return the result of calling the [[Construct]] internal method of target providing args as the arguments.
文档里说到,执行new的时候,实际上是会执行目标函数,并且把所有的参数列表传进去,也就是bind的时候传进去的加上new时传进去的参数。