How to pass arguments to addEventListener listener function?

前端 未结 30 2701
谎友^
谎友^ 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:54

    There is a special variable inside all functions: arguments. You can pass your parameters as anonymous parameters and access them (by order) through the arguments variable.

    Example:

    var someVar = some_other_function();
    someObj.addEventListener("click", function(someVar){
        some_function(arguments[0]);
    }, false);
    

提交回复
热议问题