How to fix the jslint message: variable is already defined

后端 未结 2 1627
礼貌的吻别
礼貌的吻别 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:14

    In the function, actually e has been defined as argument. so when you define some variable same as arguments, it will complains.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题