Sometimes you import libraries that contains classes & You implement some classes that you want to consider as ParentClass of the library Classes.
- Using
extends
keyword requires the existing ofParent
class Before . However, in our case,ChildClass
(library classes) has been declared beforeParentClass
.
Brief : What about if ParentClass is declared after ChildClass ?
class Car {
getNumberOfAjal(){
return 4;
}
}
class Veh {
start(){
key.turnLeft();
}
}
Now , we need to extends Car
class by Veh
class without using extends because ParentClass has been declared after ChildClass.
My attempt begins as following ;assuming that (Car
is ChildClass & Veh
is ParentClass)
Object.getOwnPropertyNames( Veh.prototype ).forEach((methodName)=>{
// How to get the parent-method itself , not only the method-name as string
//--- Anyway, .....
// Suppose Object.getMethod(Class,methodName) gives as the method
Car.prototype[methodName]= Object.getMethod(Veh,methodName);//???????
})
How should Object.getMethod
looks like ?
class Car {
RépondreSupprimergetNumberOfAjal(){
return 4;
}
}
class Veh {
start(){
key.turnLeft();
}
}
Now , we need to extends Car class by Veh class without using extends because ParentClass has been declared after ChildClass.
My attempt begins as following ;assuming that (Car is ChildClass & Veh is ParentClass)
Object.getOwnPropertyNames( Veh.prototype ).forEach((methodName)=>{
// How to get the parent-method itself , not only the method-name as string
//--- Anyway, .....
// Suppose Object.getMethod(Class,methodName) gives as the method
Car.prototype[methodName]= Object.getMethod(Veh,methodName);//???????
})
class STUDENT
RépondreSupprimer{
public void PRINTNAME(string NAME ,string ADDRESS)
{
Console.WriteLine("THIS IS ONE");
}
public void PRINTNAME(string NAME, string ADDRESS,int A)
{
Console.WriteLine("THIS {0}{1}{2}",NAME,ADDRESS,A);
}
}