0
button.onclick = function () {console.log("done");}; 
button.ondblclick = function () {console.log("done");};

If I want to decrease these lines and make them do the same function without any duplication, how can I do so?

I have a way:

function print ()
{
    console.log("click");
}

button.onclick = print;
button.ondblclick = print;

But I don't want to duplicate the calling of the function. I was thinking something like this:

if (button.onclick == True  || button.ondblclick == True)
{
  console.log("done");
}

Can this be done?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mahmoud
  • 53
  • 8

0 Answers0