只需在方法调用后返回this即可
var user = function(name, age) {
this.name = name;
this.age = age;
};
user.prototype.getName = function() {
console.log(this.name);
return this;
};
user.prototype.getAge = function() {
console.log(this.age);
return this;
};
var user1 = new user("zjf", 22);
user1.getName().getAge();
优点:可以像jQuery一样方便书写
缺点:在调试的时候,不容易找到错误点,即不利于维护