thread.js

来自「java 写的一个新闻发布系统」· JavaScript 代码 · 共 55 行

JS
55
字号
/*   DynAPI Distribution   Thread Class   The DynAPI Distribution is distributed under the terms of the GNU LGPL license.   Requirements:	dynapi.api [dynlayer, dyndocument, browser, events]*/function Thread(dlyr) {	// Inherit from object. Provides unique ID	this.DynObject = DynObject	this.DynObject()		this.setDynLayer(dlyr);}Thread.prototype = new DynObjectThread.prototype.active = false;Thread.prototype.interval = 50;Thread.prototype.cancelThread = false;Thread.prototype.sleep = function (ms) {	this.interval = Math.abs(parseInt(ms));	if (this.active) {		this.stop();		setTimeout(this+'.start()',this.interval+1);	}};Thread.prototype.setFPS = function (fps) {	this.sleep(Math.floor(1000/fps));};Thread.prototype.cancel = function () {	this.cancelThread = true;	this.stop();};Thread.prototype.start = function () {	if (!this.active) {		this.active = true;		if (!this.cancelThread) this.timer = setInterval(this+'.run()',this.interval);	}};Thread.prototype.run = function () {}; // overwrite runThread.prototype.stop = function () {	this.active = false;	if (!this.cancelThread && this.timer) {		clearInterval(this.timer);		delete this.timer;	}};Thread.prototype.setDynLayer = function (dlyr) {	this.dlyr = dlyr;};Thread.prototype.getDynLayer = function () {	return this.dlyr;};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?