实践

  1. function Animal(){
  2. this.name = 'animal';
  3. }
  4. Animal.prototype.say=function(){
  5. console.log('my name is ' + this.name);
  6. }
  7. function Bird(name,weight){
  8. this.weight = weight;
  9. return this;
  10. }
  11. Bird.prototype.fly = function(){
  12. console.log('I am a Bird, I can fly');
  13. }
  14. // Bird.prototype = new Animal();
  15. // 等价
  16. Bird.prototype.__proto__ = Animal.prototype;
  17. Animal.call(Bird.prototype);
  18. console.dir(Bird);
  19. var bird = new Bird('bird',123);
  20. console.dir(bird);
  21. bird.say()
  22. var obj = {};
  23. console.dir(obj);