[TypeScript] 0.First Example

Create a greeter.ts file:

class Student {
    fullname : string;
    constructor(public firstname, public middleinitial, public lastname) {
        this.fullname = firstname + " " + middleinitial + " " + lastname;
    }
}

interface Person {
    firstname: string;
    lastname: string;
}

function greeter(person : Person) {
    return "Hello, " + person.firstname + " " + person.lastname;
}

var user = new Student("Jane", "M.", "User");

document.body.innerHTML = greeter(user);

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<script src="greeter.js"></script>
</body>
</html>

 

Webstrom can add watcher to the ts file, it will auto convert to the javascript file.

 

posted @ 2015-03-19 16:37  Zhentiw  阅读(175)  评论(0编辑  收藏  举报