自从我学习了jQuery之后,我总是想知道jQuery如何通过添加点来执行一个接一个的函数.(不知道它的真名,对不起);
$("#somediv").fadeIn("fast").css("background","blue");
Run Code Online (Sandbox Code Playgroud)
当淡入淡出效果完成时,CSS函数执行.就像你可以一个接一个地执行你想要的任何功能一样.
我怎样才能做到这一点?
注意:如果我说错了,请纠正我,我只是想学习.
它返回相同类型的对象,这是一个非常简单的示例,演示了该技术:
var Counter = function(){
this.val = 0;
};
Counter.prototype.increment = function(){
++this.val;
return this;
};
Counter.prototype.decrement = function(){
--this.val;
return this;
};
Counter.prototype.log = function(){
console.log(this.val);
return this;
};
var o = new Counter();
o.increment().increment().decrement().log().increment().log();
Run Code Online (Sandbox Code Playgroud)