class Timer {

//js 内置的timer对象
private _jsInnerTimerObj: any;
private _enable: boolean;
private _handlerInvoker:any; private _interval: number; get Interval(): number{
return this._interval;
}
set Interval(value: number) {
this._interval = value;
//重新设定新的定时器
if (this._jsInnerTimerObj) {
window.clearInterval(this._jsInnerTimerObj);
} } private _elapsed:any; get Elapsed(): any{
return this._elapsed;
}
set Elapsed(value: any) {
/*if (!isFunction(value)) {
throw new Error("the Elapsed value must be function!");
}*/
this._elapsed = value;
//只有设置了触发事件才定时,没有回调的定时器是无意义的定时执行其中的匿名方法
this._jsInnerTimerObj = window.setInterval(this._handlerInvoker, this.Interval); } /* 构造函数
*@interval 设置定时器的毫秒数
*/
constructor(interval: number) {
this._enable = false;
this.Interval = interval;
var that = this;
this._handlerInvoker = function () {
if (that.Elapsed&&that._enable==true){
that.Elapsed();
}
}
} Start() {
this._enable = true;
}
Stop() {
this._enable = false;
}
} var t = new Timer(500);
t.Elapsed = function () {
document.write(99)
}
t.Start();

C# 的Timer 在javascript中的实现--基于Typescript的更多相关文章

  1. Javascript中prototype属性详解

    在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Javascript语言体系中,是不存在类(Class)的概念的,javascript中不 ...

  2. Javascript中prototype属性的详解

    原文链接:http://www.cnblogs.com/Uncle-Keith/p/5834289.html 在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象 ...

  3. 详解Javascript中prototype属性(推荐)

    在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Javascript语言体系中,是不存在类(Class)的概念的,javascript中不 ...

  4. 详解Javascript中prototype属性

    转自:https://www.jb51.net/article/91826.htm 在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Jav ...

  5. Javascript中prototype属性详解 (存)

    Javascript中prototype属性详解   在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Javascript语言体系中,是不 ...

  6. (转载)详解Javascript中prototype属性(推荐)

    在典型的面向对象的语言中,如java,都存在类(class)的概念,类就是对象的模板,对象就是类的实例.但是在Javascript语言体系中,是不存在类(Class)的概念的,javascript中不 ...

  7. 【JavaScript】JavaScript中的Timer是怎么工作的( setTimeout,setInterval)

    原文(http://www.yeeyan.org/articles/view/luosheng/24380) 作为入门者来说,了解JavaScript中timer的工作方式是很重要的.通常它们的表现行 ...

  8. [ Javascript ] JavaScript中的定时器(Timer) 是怎样工作的!

    作为入门者来说.了解JavaScript中timer的工作方式是非常重要的.通常它们的表现行为并非那么地直观,而这是由于它们都处在一个单一线程中.让我们先来看一看三个用来创建以及操作timer的函数. ...

  9. JavaScript中让Html页面中循环播放文字

    JavaScript中让Html页面中循环播放文字 <html> <head> <meta http-equiv="Content-Type" con ...

随机推荐

  1. C\C++各路高手以及操作系统专家请进来杀死这个进程

    通常情况下编写一个程序,能够点击关闭button正常结束程序,也能够使用任务管理器结束任务,还能够使用taskkill等命令杀死进程,实在都不行也能够直接重新启动计算机. 可是,这些方法真的都管用吗? ...

  2. sqlite3.exe 使用

    1 下载sqlite3.exe 2 命令行cmd,进入到sqlite3.exe目录 3 >sqlite3.exe database.db   来打开sqlite数据库. 4 基本语法: > ...

  3. 《Windows核心编程》第九章——用内核对象进行线程同步

    先举一个有bug的例子: #include <iostream> #include <windows.h> #include <process.h> using n ...

  4. LeetCode: Implement strStr() [027]

    [题目] Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if ...

  5. 如何高效把一字节的位对换, bit0和bit7,bit1和bit6,以此类推.

    #include<stdio.h> #include<stdlib.h> //异或法 unsigned char byteReverse(unsigned char val) ...

  6. 机器学习算法之旅A Tour of Machine Learning Algorithms

    In this post we take a tour of the most popular machine learning algorithms. It is useful to tour th ...

  7. 【BZOJ】【1941】【SDOI2010】Hide and Seek

    KD-Tree 一开始看错题了

  8. 【Codeforces】【#295】【Div.2】

    o(︶︿︶)o 唉跪烂了…… B题由于考虑的不周全WA了3次…… C题由于#include了<cmath>,而我函数声明的是pow(LL a,LL b)但调用的时候 [没!有!把!n!的! ...

  9. OpenCV学习(17) 细化算法(5)

    本章我们看下Pavlidis细化算法,参考资料http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/con ...

  10. Android Studio体验(二)--创建项目和Genymotion试用

    上周日已经体验了一把Android Studio顺便没事点了点其他功能,不过还是从自己创建项目开始说吧,首先我们要熟悉Android Studio中的Project 和 Module 两个概念.And ...