js static and instance members

<! DOCTYPE HTML > 
< HTML lang = "EN" > 
< head > 
  < Meta charset = "UTF-. 8" > 
  < title > the Document </ title > 
</ head > 
< body > 
  < Script > 
    function Hero (name, Blood , Weapon) {
       // instance members / member objects - objects associated with members of the future use objects way to invoke 
      the this .name = name;
       the this . Blood = Blood;
       the this .weapon = Weapon; 

      the this .attack =  function () { 
        the console.log ( the this .weapon +  ' attack the enemy ' ); 
      } 
    } 

    // static member - member added to the constructor directly 
    Hero.version =  ' 1.0 ' ; 
    

    var Hero =  new new Hero ( ' Bei ' , 100 , ' swords ' ); 
    hero.attack (); 

    var hero1 =  new new Hero ( ' Guan ', 100 , ' knife ' ); 
    hero1.attack (); 
    // mode can not be used to invoke the object's static member 
    the console.log (hero.version); 

    // static member using a constructor to call 
    console.log (Hero.version );
   </ Script > 
</ body > 
</ HTML >

 

Guess you like

Origin www.cnblogs.com/jiumen/p/11430170.html