为什么要应用Function.prototype.bind.bind?

Bvgheluwe

我了解Function.prototype.bind.apply运作方式。假设以下定义:

var Constructor = function(someArgument){
    //constructor body here
};

var creator = function(ctor, args){
    args.unshift(null); //or anything else to make 'bind' succeed
    return new (Function.prototype.bind.apply(ctor, args));
};

var creator2 = function(ctor, args){
    return new ctor(args);
};

var obj = creator(Constructor, ['someVar']);
var obj2 = creator2(Constructor, ['someVar']);

无论creatorcreator2工作,那么,为什么一个选择creatorcreator2

ak

调用creator2args数组作为单个数组参数传递给构造函数。

调用creator将数组中的每个项目作为单独的参数传递(通过apply)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Function.prototype.apply.bind用法?

来自分类Dev

以null为参数的Function.prototype.bind

来自分类Dev

Function.prototype.apply.bind用法?

来自分类Dev

Function.prototype.bind 与 arguments 对象

来自分类Dev

Function.prototype.bind()会一直很慢吗?

来自分类Dev

Function.prototype.bind.apply()无法正常工作

来自分类Dev

使用Function.prototype.bind和参数数组?

来自分类Dev

Javascript:function.prototype.bind()中的参数解包?

来自分类Dev

回调中function.prototype.bind的替代方法

来自分类Dev

即使在应该支持的版本中,Function.prototype.bind在IE中也不起作用

来自分类Dev

Function.prototype.call.bind如何在此代码中工作

来自分类Dev

使用javascript的Function.prototype.bind()测试变量是否为特定的绑定函数

来自分类Dev

.bind()的用途是什么

来自分类Dev

为什么Bind.bind在Scalaz 7中实现Bind.ap

来自分类Dev

为什么不建议使用bind()?

来自分类Dev

为什么在此示例中使用.bind()?

来自分类Dev

function(){}。bind(this)和angular.bind(this,function(){})之间的区别

来自分类Dev

Bind callback function with multiple arguments

来自分类Dev

为什么data-amp-bind-href或[href]在amp-bind组件中不起作用?

来自分类Dev

Object.prototype和bind()方法如何一起工作

来自分类Dev

什么是PDO上的bind_result

来自分类Dev

在Redis中,bind参数有什么作用?

来自分类Dev

什么是Ember.bind,它如何工作?

来自分类Dev

std :: bind分配给std :: function

来自分类Dev

How to bind arguments to child function in Vue

来自分类Dev

使用std :: bind和std :: function

来自分类Dev

Event handler function to wxButton with Bind() - wxWidgets 3.0

来自分类Dev

使用boost :: function和boost :: bind

来自分类Dev

Python替代Javascript function.bind()吗?

Related 相关文章

  1. 1

    Function.prototype.apply.bind用法?

  2. 2

    以null为参数的Function.prototype.bind

  3. 3

    Function.prototype.apply.bind用法?

  4. 4

    Function.prototype.bind 与 arguments 对象

  5. 5

    Function.prototype.bind()会一直很慢吗?

  6. 6

    Function.prototype.bind.apply()无法正常工作

  7. 7

    使用Function.prototype.bind和参数数组?

  8. 8

    Javascript:function.prototype.bind()中的参数解包?

  9. 9

    回调中function.prototype.bind的替代方法

  10. 10

    即使在应该支持的版本中,Function.prototype.bind在IE中也不起作用

  11. 11

    Function.prototype.call.bind如何在此代码中工作

  12. 12

    使用javascript的Function.prototype.bind()测试变量是否为特定的绑定函数

  13. 13

    .bind()的用途是什么

  14. 14

    为什么Bind.bind在Scalaz 7中实现Bind.ap

  15. 15

    为什么不建议使用bind()?

  16. 16

    为什么在此示例中使用.bind()?

  17. 17

    function(){}。bind(this)和angular.bind(this,function(){})之间的区别

  18. 18

    Bind callback function with multiple arguments

  19. 19

    为什么data-amp-bind-href或[href]在amp-bind组件中不起作用?

  20. 20

    Object.prototype和bind()方法如何一起工作

  21. 21

    什么是PDO上的bind_result

  22. 22

    在Redis中,bind参数有什么作用?

  23. 23

    什么是Ember.bind,它如何工作?

  24. 24

    std :: bind分配给std :: function

  25. 25

    How to bind arguments to child function in Vue

  26. 26

    使用std :: bind和std :: function

  27. 27

    Event handler function to wxButton with Bind() - wxWidgets 3.0

  28. 28

    使用boost :: function和boost :: bind

  29. 29

    Python替代Javascript function.bind()吗?

热门标签

归档