Skip to content

Instantly share code, notes, and snippets.

@shadow-prince
Last active April 9, 2021 17:30
Show Gist options
  • Save shadow-prince/69020fbfc58ccf980f9b209053e95f54 to your computer and use it in GitHub Desktop.
Save shadow-prince/69020fbfc58ccf980f9b209053e95f54 to your computer and use it in GitHub Desktop.
Refer these for inheritance and more...🎈
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);
}
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();
});
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;
}
}
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