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

猜你喜欢

转载自blog.csdn.net/document_ljt/article/details/83089089
今日推荐