How to fix the jslint message: variable is already defined

后端 未结 2 1626
礼貌的吻别
礼貌的吻别 2021-01-22 05:00

I was trying to implement the following code:

var action = function (e) {     
    if (!e) {
        var e = window.event;
    }
    e.cancelBubble = true;
    i         


        
2条回答
  •  一整个雨季
    2021-01-22 05:23

    Using a named argument creates a locally scoped variable (which is what var does). Since you have an argument e and you use var e you are trying to create the variable twice.

    Remove the var from where you use e the third time time.

    var event = function (e) {      // First time
        if (!e) {                   // Second time
            e = window.event;       // Third time
    

提交回复
热议问题