Skip to content

Instantly share code, notes, and snippets.

@kenmori
Last active March 19, 2017 10:54
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 kenmori/6485bc761d97a934f61d to your computer and use it in GitHub Desktop.
Save kenmori/6485bc761d97a934f61d to your computer and use it in GitHub Desktop.
【TypeScript】super()の使い方理解する。(親Classのメソッドを使用、値を渡す) ref: http://qiita.com/M-ISO/items/bed1be20c8eaab1c7762
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Person = (function () {
function Person(name) {
this.name = name;
}
return Person;
})();
var PersonFunc = (function (_super) {
__extends(PersonFunc, _super);
function PersonFunc() {
_super.apply(this, arguments);
}
PersonFunc.prototype.get = function () {
alert(this.name + 'ちゃん!'); //親のnameを参照
//returnするものを定義
};
return PersonFunc;
})(Person);
var MoritaGetMajide = (function (_super) {
__extends(MoritaGetMajide, _super);
function MoritaGetMajide() {
//コンストラクタに引数は不要、ただ必要な値を親にわたす
_super.call(this, 'けんじ'); //これ必要
}
return MoritaGetMajide;
})(PersonFunc);
var fafa = new MoritaGetMajide();
fafa.get(); //けんじちゃん
class Person {
constructor(public name:string){
}
}
class PersonFunc extends Person{
get(){
alert(this.name + 'ちゃん!');//親のnameを参照
//returnするものを定義
}
}
class MoritaGetMajide extends PersonFunc{
constructor(){
//コンストラクタに引数は不要、ただ必要な値を親にわたす
super('けんじ')//これ必要
}
}
var fafa = new MoritaGetMajide();
fafa.get()//けんじちゃん
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment