Last active
April 9, 2021 17:30
-
-
Save shadow-prince/69020fbfc58ccf980f9b209053e95f54 to your computer and use it in GitHub Desktop.
Refer these for inheritance and more...π
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
import { Mobile } from "./Mobile"; | |
export class BasicPhone extends Mobile{ | |
mobileType:string; | |
constructor(mobileName:string,mobileCost:number,mobileId: number,mobileType:string){ | |
super(mobileId, mobileName, mobileCost); | |
this.mobileType=mobileType; | |
} | |
printMobileDetails = ()=> console.log("Mobile Name: "+ this.mobileName+", "+"Mobile cost "+this.mobileCost+", "+"Mobile Type: "+this.mobileType); | |
} | |
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
import { BasicPhone } from "./BasicPhone"; | |
import { SmartPhone } from "./SmartPhone"; | |
let mobileArray:(BasicPhone | SmartPhone)[] = [new BasicPhone("Karbon",1500,2,"Flat"), new SmartPhone("Samsung",500,5,"Slim")]; | |
/* | |
for (const key of mobileArray) { | |
console.log(key.printMobileDetails()); | |
} | |
? Lets do this using forEach | |
*/ | |
mobileArray.forEach(element => { | |
element.printMobileDetails(); | |
}); |
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
export class Mobile { | |
mobileId: number; | |
mobileName: string; | |
mobileCost: number; | |
constructor(mobileId: number, mobileName: string, mobileCost: number) { | |
this.mobileCost = mobileCost; | |
this.mobileId = mobileId; | |
this.mobileName = mobileName; | |
} | |
} |
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
import { Mobile } from "./Mobile"; | |
export class SmartPhone extends Mobile{ | |
mobileType:string; | |
constructor(mobileName:string,mobileCost:number,mobileId: number,mobileType:string){ | |
super(mobileId, mobileName, mobileCost); | |
this.mobileType=mobileType; | |
} | |
// My Arrow ==> way of dealing with stuff | |
printMobileDetails = ()=>console.log("Mobile Name: "+ this.mobileName+", "+"Mobile cost "+this.mobileCost+", "+"Mobile Type: "+this.mobileType); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment