Javascript-9-1-OOP-5-链式调用
<html lang="en"> <head> </head> <body> <div class="" style="width: 0px;height: 50px;border: 3px solid black" id="div1"> </div> <script type="text/javascript"> var i=0; function Adder(){ Adder.prototype.styleAdder=function(divId,width) { document.getElementById(divId).style.width = width+"px"; return this;//this总是指向Adder()的实例,链式调用关键点 }; } var adder=new Adder(); adder.styleAdder("div1",50).styleAdder("div1",160).styleAdder("div1",360); </script> </body> </html>