Discuss / JavaScript / show一波操作

show一波操作

Topic source
function Cat(name){
    this.name = name;
}
Cat.prototype.say = function(){
    return "hello," + this.name;
};
var cat1 = new Cat("cat1");
console.log(cat1.say()); //hello,cat1
var cat2 = new Cat("cat2");
console.log(cat2.say()); //hello,cat2
console.log(cat1.say === cat2.say); //true

  • 1

Reply