所有的实例对象共享同一个prototype对象,那么从外界看起来,prototype对象就好像是实例对象的原型,而实例对象则好像"继承"了prototype对象一样。

 

 

<script>
 //var x = "555"
 function Dog(x){
  this.Name = x;
 }
 /*
 Dog.prototype.speak = function(){
  alert("It can speak!");
 }
 Dog.prototype.length="10";
 */
 Dog.prototype = {species: '犬科',food:"bread",eats:function(){
  alert("I can eat everything");
 }};
 Dog.prototype.speak = function(){
  alert("I can't Spak");
 }
 var dogA = new Dog("DDD");
 dogA.eats();
 dogA.speak();
</script>

相关文章:

  • 2021-07-23
  • 2021-07-28
  • 2021-11-09
  • 2021-08-22
  • 2021-08-07
  • 2021-04-13
  • 2021-06-15
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2021-09-12
  • 2021-11-23
  • 2022-02-04
  • 2022-01-16
相关资源
相似解决方案