UNPKG

ascor

Version:

一些常用的简单的js工具

41 lines (40 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Timer = void 0; var getCurrentTime_1 = require("./getCurrentTime"); /** * 计时器,例:new Timer() */ exports.Timer = /** @class */ (function () { function class_1() { this.isStart = false; this.begin = getCurrentTime_1.getCurrentTime(true); } /** * 开始计时 */ class_1.prototype.start = function () { if (!this.isStart) { this.isStart = true; } this.begin = getCurrentTime_1.getCurrentTime(true); }; /** * 步进,执行一次返回经过的时间毫秒数 */ class_1.prototype.step = function () { if (!this.isStart) { return 0; } return getCurrentTime_1.getCurrentTime(true) - this.begin; }; /** * 停止计时,返回经过的毫秒数 */ class_1.prototype.stop = function () { var s = this.step(); this.isStart = false; return s; }; return class_1; }());