UNPKG

ascor

Version:

一些常用的简单的js工具

38 lines (37 loc) 898 B
import { getCurrentTime } from "./getCurrentTime"; /** * 计时器,例:new Timer() */ export var Timer = /** @class */ (function () { function class_1() { this.isStart = false; this.begin = getCurrentTime(true); } /** * 开始计时 */ class_1.prototype.start = function () { if (!this.isStart) { this.isStart = true; } this.begin = getCurrentTime(true); }; /** * 步进,执行一次返回经过的时间毫秒数 */ class_1.prototype.step = function () { if (!this.isStart) { return 0; } return getCurrentTime(true) - this.begin; }; /** * 停止计时,返回经过的毫秒数 */ class_1.prototype.stop = function () { var s = this.step(); this.isStart = false; return s; }; return class_1; }());