function Cat(name) { this.name = name; } Cat.prototype.say = function(){ return "Hello, "+this.name+"!"; }
有点不解的时Cat.prototype.say方法里的this指向的是kitty还是Cat.prototype
指向的是kitty
this是当前对象,也就是:
var kitty = new Cat('Kitty'); kitty.say(); // this指向变量kitty
Sign in to make a reply
jaychang87
有点不解的时Cat.prototype.say方法里的this指向的是kitty还是Cat.prototype