mardi 19 juillet 2016

extends class after declation (existing in minified library)

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 of Parent class Before . However, in our case, ChildClass (library classes) has been declared before ParentClass.

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 ?





2 commentaires:

  1. 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);//???????
    })

    RépondreSupprimer
  2. class STUDENT
    {
    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);


    }

    }

    RépondreSupprimer