首页 > 其他 > 详细

The bind() Method

时间:2019-05-13 22:47:42      阅读:133      评论:0      收藏:0      [点我收藏+]

The bind() method was added in ESMAScript 5, but it is easy to simulate in ESMAScrpt 3. As its name implies, the primary purpose of bind() is to bind a function to an object. When you invoke the bind() method on a function f and pass an object o,the method returns a new function. Invoking the new function (as a function) invokes the original function f as a method of o. Any arguments you pass to the new function are passed to the original function. For example:                   

          function f(y) { return this.x + y; }  // This function need to be bound
          var o = { x:1 };                             //  An object we‘ll bind to
          var g = f.bind(o);                         //  Calling g(x) invokes o.f(x)
          g(2);                                            //  => 3
                                                           

The bind() Method

原文:https://www.cnblogs.com/tsai-87/p/10859274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!