Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created July 6, 2017 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save changtimwu/902359d24d381496c0c98f9e1183fc17 to your computer and use it in GitHub Desktop.
Save changtimwu/902359d24d381496c0c98f9e1183fc17 to your computer and use it in GitHub Desktop.
some ts example
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