一个简单的链式调用
//需求num不等于1,2,3
function Fn(num){
this.num = num;
};
Fn.prototype.checkOne = function(){
if(this.num != 1){
return this;
}else{
return false;
}
}
Fn.prototype.checkTwo = function(){
if(this.num != 2){
console.log("not 2");
return this;
}else{
return false;
}
}
Fn.prototype.checkThree = function(){
if(this.num != 3){
console.log("not 3");
return this;
}else{
return false;
}
}
var f = new Fn(2);
try{
f.checkOne().checkTwo().checkThree();
}catch(e){
console.log("num不符合需求");
}