Working on my framework again. Wanted to create a method to blink an element. I would need to set interval inside the method. So I thought this might work:
var optionalSelector = "$";
(function() {
(this[arguments[0]] = function constructor(input) {
if (!(this instanceof constructor)) { return new constructor(input); }
this.elm = document.getElementById(input);
}).prototype = {
blink: function() {
function changeDisplay() {
if (this.elm.style.display != "none") {
this.elm.style.display = "none";
} else {
this.elm.style.display = "block";
}
}
setInterval(changeDisplay, 1000);
},
};
})(optionalSelector);
And calling the method $("anElmId").blink();
But it doesn't. Another function inside the method and there's also an interval. I guess this two messes things up. Like it doesn't recognize this.elm
. Since I'm a newbie I couldn't figure out a way to fix this. Any ideas?