Skip to content

Instantly share code, notes, and snippets.

@cohama
Created October 13, 2012 04:27
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 cohama/3883219 to your computer and use it in GitHub Desktop.
Save cohama/3883219 to your computer and use it in GitHub Desktop.
TypeScript のオブジェクト志向練習
interface IGreeter {
greet(): string;
}
class NameGreeter implements IGreeter {
constructor(public name: string) {}
public greet(): string {return this.name}
}
class CountGreeter implements IGreeter {
private count: number = 0;
public greet(): string {return this.count++ + "th";}
}
var ng = new NameGreeter("John")
var cg = new CountGreeter()
function greetLog(greeter: IGreeter) {
console.log(greeter.greet())
}
greetLog(ng)
greetLog(cg)
greetLog(cg)
greetLog(cg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment