javascript - How to understand this onclick statement?
高洛峰
高洛峰 2017-05-18 10:53:43
0
2
426

is link[i].onclick = Why are the two brackets ()() used together? How to understand?

As shown below:

Please tell me! Thanks!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
滿天的星座

Assumption:

var test = function(i) {
    return function() {
        alert(i+1);
    }
}

So your above line can also be written like this:

links[i].onclick = test(i);

The first bracket is to wrap the function name, and the second bracket is to indicate the method parameters

習慣沉默

Self-executing function, indicating that it directly points to the content of function return.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template