Created
July 6, 2017 18:45
-
-
Save changtimwu/902359d24d381496c0c98f9e1183fc17 to your computer and use it in GitHub Desktop.
some ts example
This file contains hidden or 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 Greeter { | |
greeting: string; | |
constructor(message: string) { | |
this.greeting = message; | |
} | |
greet() { | |
return "Hello, " + this.greeting; | |
} | |
} | |
let classof = (instance) => instance.constructor.name | |
let greeter = new Greeter("world"); | |
let button = document.createElement('button'); | |
let result = document.createElement('textarea'); | |
result.rows = 30 | |
result.cols=30 | |
function log(fmt: string, ...args: any[]): void { | |
let s = fmt+args[0] | |
result.value = result.value +"\n"+ s | |
} | |
button.textContent = "RUN"; | |
button.onclick = function() { | |
console.log(greeter.greet()) | |
var anum: number = 3 | |
var astr: string = 'hello' | |
log('instance class is ', classof(greeter)) | |
log('anum class=', classof(anum)) | |
log('astr=', classof(astr)) | |
} | |
document.body.appendChild(button); | |
document.body.appendChild( result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment