简体   繁体   中英

Can member-methods of objects be called without bind?

Is there a way to call inc of obj without bind?

 function callIt(callback){
   callback();
 }

 var obj = {
    count: 0,
    inc: function(){
       this.count++;
    }
 };

 callIt(obj.inc.bind(obj));
 obj.count;// 1

Question is relevant to me because of older IE-versions that do not support the method bind.

您可以使用函数值

callIt(function() { obj.inc(); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM