[英]Calling a function listed inside a prototype
CircularCountDown.prototype = {
init: function () {
this.formatData();
this.draw();
this.start();
},
start: function () {
if (typeof this.data.beforeStart == "function") {
this.data.beforeStart(this);
}
this.show();
this.starDecrementTimeEvent();
var time = this.getFormattedTimeByCircle();
this.animate(time);
},
starDecrementTimeEvent: function () {
var that = this;
console.log(that);
this.decrementTimeEvent = setInterval(function () {
that.time -= 1;
that.setTime(that.getStringTime(that.time));
if (that.time <= 0) {
that.time = 0;
that.stopDecrementTimeEvent();
if (typeof that.data.end == "function") {
that.data.end(that);
}
}
}, 1000);
},
stopDecrementTimeEvent: function () {
clearInterval(this.decrementTimeEvent);
}
}
我正在為循環計時器使用插件,並且正在尋找調用stopDecrementTimeEvent函數以在其他JS文件中停止計時器。 我不熟悉如何以這種格式調用它。
任何指導都會很棒,謝謝。
我正在為循環計時器使用插件,並且正在尋找調用stopDecrementTimeEvent函數以在其他JS文件中停止計時器。 我不熟悉如何以這種格式調用它
您將擁有一個通過new CircularCountDown
創建的實例 ,例如:
var theInstance = new CircularCountDown(/*...args here if needed...*/);
創建的實例(對象)將把CircularCountDown.prototype
稱為其原型的對象,這意味着它繼承了其所有屬性。
因此,您只需在該實例上調用stopDecrementTimeEvent
:
theInstance.stopDecrementTimeEvent();
這將找物業stopDecrementTimeEvent
的原型,然后把它this
參照實例(對象),這將在其計時器手柄decrementTimeEvent
財產,准備通過使用stopDecrementTimeEvent
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.