TS

//html文件
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>TypeScript HTML App_for_test</title>
    </head>
    <body>
        <h1>TypeScript HTML App_for_test</h1>
    </body>
    <script src="app.js"></script>
</html>

//app.js内容
class Greeter {
    constructor(public greeting: string) {
    }
greet() {
    return "<h1>" + this.greeting + "</h1>";
    }
};

var greeter = new Greeter("hello,world");
var str = greeter.greet();
document.body.innerHTML = str;

/***************************************************************/

class RayTracer {
    private maxDepth = 5;
    private intersections() {

    }

private testRay() {

    }

render() {
    }
};
function defaultScene(): Scene {
    return {
    }
}
function exec() {
    var canv = document.createElement("canvas");
    canv.width = 256;
    canv.height = 256;
    document.body.appendChild(canv);
    var ctx = canv.getContext("2d");
    var rayTracer = new RayTracer();
    return rayTracer.render( defaultScene() );
    }
exec()

  //第一次使用typescript,为毛感觉和js差那么多啊,太不习惯了

interface

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

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

var user = {firstname: "Jane", lastname: "User"};

document.body.innerHTML = greeter(user);

  

posted @ 2014-02-21 10:43  方方和圆圆  阅读(347)  评论(0编辑  收藏  举报

再过一百年, 我会在哪里?