1. 程式人生 > >jquery鏈式操作的封裝

jquery鏈式操作的封裝

原理很簡單每次執行完函式返回this  

 直接上程式碼

function test(){
  this.name;
  this.age;
}
test.prototype.testChild=function(){
 this.name="demo"
return this
}

test.prototype.testChild2=function(){
 this.age=20
return this.name+":"+this.age
}

var a=new test()

var b=a.testChild().testChild2()

console.log(b)//demo:20