调用原型中列出的函数
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
使用。
相关文章:
- 创建对象函数原型和代码是错误的
- 使用sinon.js创建一个“;“间谍对象”;使用基于真实构造函数/原型的间谍方法
- 使用构造函数 - 原型从文本框输出值
- 为什么函数对象的实例没有继承函数原型属性
- 获取函数原型的源代码
- 挂钩文档.使用函数原型创建元素
- 理解函数原型和__proto__
- 在Javascript的函数原型中创建函数
- Emberjs :哈希中的函数原型
- Javascript函数在父函数原型中带有原型
- 构造函数原型-继承混淆
- 本地作用域函数原型覆盖
- 使用函数原型的 JavaScript 继承问题
- 为什么我的代码认为 canvas 函数在 JavaScript 中的构造函数原型中是未定义的
- 所有内容也都链接到函数原型
- Javascript MDN 函数原型绑定 polyfill 在数组中是可枚举的
- Javascript将对象传递给函数原型
- 我应该使用构造函数/原型吗?
- 为什么函数原型不能修改 .
- 删除函数原型对象