TypeScript Ders Notları #4 Kalıtım (Inheritance)
TypeScript:
This file contains 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 Urun | |
{ | |
constructor(public ad: string) | |
{ | |
} | |
satinAl(adet: number = 0) | |
{ | |
console.log(`${adet} adet ${this.ad} alındı.`); | |
} | |
} | |
class Film extends Urun | |
{ | |
constructor(ad: string) | |
{ | |
super(ad); | |
} | |
satinAl(adet = 10) | |
{ | |
console.log("Film stoklarda..."); | |
super.satinAl(adet); | |
} | |
} | |
class Kitap extends Urun | |
{ | |
constructor(ad: string) | |
{ | |
super(ad); | |
} | |
satinAl(adet = 20) | |
{ | |
console.log("Kitap stoklarda..."); | |
super.satinAl(adet); | |
} | |
} | |
let matrix = new Film("Matrix"); | |
let seker: Urun = new Kitap("Şeker Portakalı"); | |
matrix.satinAl(); | |
seker.satinAl(25); |
This file contains 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 () { | |
var extendStatics = Object.setPrototypeOf || | |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | |
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | |
return function (d, b) { | |
extendStatics(d, b); | |
function __() { this.constructor = d; } | |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | |
}; | |
})(); | |
var Urun = (function () { | |
function Urun(ad) { | |
this.ad = ad; | |
} | |
Urun.prototype.satinAl = function (adet) { | |
if (adet === void 0) { adet = 0; } | |
console.log(adet + " adet " + this.ad + " al\u0131nd\u0131."); | |
}; | |
return Urun; | |
}()); | |
var Film = (function (_super) { | |
__extends(Film, _super); | |
function Film(ad) { | |
return _super.call(this, ad) || this; | |
} | |
Film.prototype.satinAl = function (adet) { | |
if (adet === void 0) { adet = 10; } | |
console.log("Film stoklarda..."); | |
_super.prototype.satinAl.call(this, adet); | |
}; | |
return Film; | |
}(Urun)); | |
var Kitap = (function (_super) { | |
__extends(Kitap, _super); | |
function Kitap(ad) { | |
return _super.call(this, ad) || this; | |
} | |
Kitap.prototype.satinAl = function (adet) { | |
if (adet === void 0) { adet = 20; } | |
console.log("Kitap stoklarda..."); | |
_super.prototype.satinAl.call(this, adet); | |
}; | |
return Kitap; | |
}(Urun)); | |
var matrix = new Film("Matrix"); | |
var seker = new Kitap("Şeker Portakalı"); | |
matrix.satinAl(); | |
seker.satinAl(25); |
Hiç yorum yok:
Yorum Gönder