Typescript中的Class

let btn = document.createElement('button');
btn.textContent = 'Say Hello';
document.body.appendChild(btn);

class SayHello {
    name: string;
    constructor(message: string) {
        this.name = message;
    }
    greet() {
        return 'Hello' + this.name;
    }
}
let greeting = new SayHello('World!');

btn.addEventListener('click', function () {
    alert(greeting.greet());
})

  

正如图上所显示 typescript 操作dom 和Js没有什么区别 只是提前用了es6的class语法糖

 

posted @ 2017-01-16 09:51  Mrzwq  阅读(309)  评论(0编辑  收藏  举报