Reputation: 153
Js class method getInfo should call alert after 5 seconds delay, but it fires immediately
function limiter (limit,hid,sid) {
this.limit = limit;
this.hid = hid;
this.sid = sid;
this.getInfo = function(aca) {
setTimeout(alert(aca), 5000);
};
}
var limiter= new limiter(5,5,5);
limiter.getInfo("loko roko");
Upvotes: 0
Views: 69
Reputation: 41893
Place the alert
event inside a function.
function limiter(limit, hid, sid) {
this.limit = limit;
this.hid = hid;
this.sid = sid;
console.log(this.limit);
this.getInfo = function(aca) {
setTimeout(() => {
console.log(this.limit);
alert(aca)
}, 5000);
};
}
var limiter = new limiter(5, 5, 5);
limiter.getInfo("loko roko");
Upvotes: 3