javascript基础学习二:prototype
function Cat(name, color) { this.name = name; this.color = color; } Cat.prototype.type = "猫科动物"; Cat.prototype.eat = function(){ console.log("吃鱼吃老鼠"); } var c1 = new Cat("Tom", "black"); console.log(c1.type); c1.eat();
//检测类与对象人性关系:isPrototypeOf
Cat.prototype.isPrototypeOf(c1) //true