Created
September 16, 2017 16:23
-
-
Save kuzmicheff/aee79e966596d3242f897b8a6e6000b8 to your computer and use it in GitHub Desktop.
Simple greeter in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>TypeScript Greeter</title> | |
</head> | |
<body> | |
<script src="greeter.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "Hello, " + person.firstName + " " + person.lastName; | |
} | |
var user = new Student("Andre", "N", "Kuzmicheff"); | |
document.body.innerHTML = greeter(user); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Andre", "N", "Kuzmicheff"); | |
document.body.innerHTML = greeter(user); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment