How to pass arguments to addEventListener listener function?

前端 未结 30 2267
谎友^
谎友^ 2020-11-21 23:56

The situation is somewhat like-

var someVar = some_other_function();
someObj.addEventListener(\"click\", function(){
    some_function(someVar);
}, false);
<         


        
30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 00:40

    I have very simplistic approach. This may work for others as it helped me. It is... When you are having multiple elements/variables assigned a same function and you want to pass the reference, the simplest solution is...

    function Name()
    {
    
    this.methodName = "Value"
    
    }
    

    That's it. It worked for me. So simple.

提交回复
热议问题