JS Advanced --- prototype method is that you can access each other (call) of

The prototype method is accessible to each other (call) of

Method prototype, can visit each other, call each other
 
<!DOCTYPE html>
<html lang="en">

< Head > 
  < Meta charset = "UTF-. 8" > 
  < title > title </ title > 
  < Script > 
    // Method prototype, is accessible to each other 
    function Animal (name, Age) {
       the this .name = name;
       the this .age = Age;
    }

    // add prototype method 
    Animal.prototype.eat =  function () {
      console.log ( " eat bamboo " );
       the this .play ();
    };

    Animal.prototype.play = function () {
      console.log("玩球");
      this.sleep();
    }

    Animal.prototype.sleep = function () {
      console.log ( " sleep " );
    }

    // instantiates and initializes 
    var Panda =  new new Animal ( " daughter " , 9 );
    panda.eat (); // call the method
    // Method prototype object, you can call each 
  </ Script > 
</ head >

<body>


</body>

</html>

Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/12109309.html