(function($) {
var list = $("content").children,
len = list.length,
begin = $("begin"),
index = 0,
interval = null;
begin.onclick = function() {
if (this.running) return;
this.running = true;
this.remain = 3000 + Math.random() * 5000;
interval = setInterval(function() {
if (begin.remain < 200) {
begin.running = false;
alert(": " + list[index].innerHTML);
clearInterval(interval);
} else {
list[index].className = "";
list[(index + 1) % len].className = "current";
index = PPindex % len;
begin.remain -= 100;
}
}, 100);
};
var mm = 3;
window.fn = function() {
alert(mm);
};
mm += 3;
})(function(id) {
return document.getElementById(id)
});
I saw such a code about the lucky draw on the Internet. I still want to give some advice on what I don"t understand. Here is my understanding. If my understanding is wrong, I hope I can give you a lot of advice. Thank you!
it is known that this is a self-executing function, and the argument of the function is the function at the other end.
so is the parameter $
in the self-executing function related to the $
that gets the element in the specific code (for example: $("begin")
)
in addition, this
in begin.onclick
should point to begin
(that is, $("begin")
), so how to understand this.running
, this.remain
, running
and remain
on begin
prototype?