1、什么是链式调用
这个很容易理解,例如:一般的函数调用和链式调用的区别:调用完方法后,return this返回当前调用方法的对象。
<div class="jb51code">
<pre class="brush:js;">
function Dog(){
this.run= function(){
alert("The dog is running....");
return this;//返回当前对象 Dog
};
this.eat= function(){
alert("After running the dog is eatting....");
return this;//返回当前对象 Dog
};
this.sleep= function(){
alert("After eatting the dog is running....");
return this;//返回当前对象 Dog
};
}
//一般的调用方式;
/ var dog1 =new Dog();
dog1.run();
dog1.eat();
dog1.sleep();/
var dog2 = new Dog();
dog2.run().eat().sleep();