TypeScriptã®interfaceå¶éã®extendsã¨ãã¤ãã§ã«ããã¯ã¿ã¤ãã³ã°ã®ã¡ã¢
åé¡
- interfaceã£ã¦extendsã§ãããã ã£ãï¼
- ã¡ã½ããã¨ããããã£ããæºããã¦ãã°åå¶ç´çªç ´ã§ãããã ã£ãï¼ï¼ããã¯ã¿ã¤ãã³ã°ï¼
ã¡ã¢
interface Speaker { Speak(s: string): void; } interface Person extends Speaker { name: string; Greet(): void; } class Duck { constructor(public name: string) {} public Speak(s: string) { console.log(s); } public Greet() { this.Speak("人éãããªããã©ãã¼ãã" + this.name); } } var d: Person = new Duck("ããã«ã"); d.Greet();
ç¡äºãã«ãã§ããããã«ãå¾ã®js
var Duck = (function () { function Duck(name) { this.name = name; } Duck.prototype.Speak = function (s) { console.log(s); }; Duck.prototype.Greet = function () { this.Speak("人éãããªããã©ãã¼ãã" + this.name); }; return Duck; })(); var d = new Duck("ããã«ã"); d.Greet();