JSFiddle - React, Tailwind, and code Playground

by booktu8

JavaScript

//传统构造函数继承
function Animal() {
    this.eat = function () {
        console.log('Animal eat')
    }
}
function Dog() {
    this.bark = function () {
        console.log('Dog bark')
    }
}
Dog.prototype = new Animal()// 绑定原型,实现继承
/* Dog.prototype.constructor = Dog */
/* Dog.prototype */
var hashiqi = new Dog()
console.log(hashiqi,Dog.prototype.constructor)
hashiqi.bark()//Dog bark
hashiqi.eat()//Animal eat