-
-
Save kenmori/6485bc761d97a934f61d to your computer and use it in GitHub Desktop.
【TypeScript】super()の使い方理解する。(親Classのメソッドを使用、値を渡す) ref: http://qiita.com/M-ISO/items/bed1be20c8eaab1c7762
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
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(); //けんじちゃん |
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 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