Using this in event handler in strict javascript?

前端 未结 3 1855
别那么骄傲
别那么骄傲 2021-01-25 19:49

Suppose you have a routine like the following to wire up click event handlers

getElements(\".board>div\").forEach(function(elem){
  elem.addEventListener(\"cl         


        
3条回答
  •  青春惊慌失措
    2021-01-25 20:23

    Your use of this is valid. To suppress the this errors in your event handler add /*jshint validthis: true */ to the top of the function.

    Found that here: https://stackoverflow.com/a/16553290/552067

提交回复
热议问题