首页 > 其他 > 详细

Typescript 实现链表

时间:2015-09-09 13:17:39      阅读:269      评论:0      收藏:0      [点我收藏+]

来看看怎么用typescript实现链表:

 

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

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

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

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

while (user!=null) {
    document.body.innerHTML += greeter(user);
    user = user.Next;
}

 生成的JavaScript:

var Student = (function () {
    function Student(firstname, middleinitial, lastname) {
        this.firstname = firstname;
        this.middleinitial = middleinitial;
        this.lastname = lastname;
        this.fullname = firstname + " " + middleinitial + " " + lastname;
    }
    return Student;
})();
function greeter(person) {
    return "<h1>Hello, " + person.firstname + " " + person.lastname + "</h1>";
}
var user = new Student("Jane", "M.", "User");
user.Next = new Student("Tony", "Mr.", "Student");
while (user != null) {
    document.body.innerHTML += greeter(user);
    user = user.Next;
}
//# sourceMappingURL=greeter.js.map

 

Typescript 实现链表

原文:http://www.cnblogs.com/ByronWu12345/p/4794104.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!