I've a question about chainability, look at this code:
document.getElementById('menu').fadeIn(200, function(){ //callback });
How can i make this without jQuery?
Note: the name fadeIn() and fadeOut() are for example, there are not the jQuery functions.
"Method chaining is a common technique for invoking multiple method calls in object-oriented programming languages. Each method returns an object (possibly the current object itself), allowing the calls to be chained together in a single statement.A method chain is also known as a train wreck due to an increasing amount of methods stacked after another in one line."
//Create an object which contains functions
var obj={
alert : function(txt){
alert(txt);
return this //return itself
},
confirm :function(txt){
confirm(txt);
return this //return itself
}
}
//Now you can chain as much as you want
obj.alert("This").alert("is").confirm("called").alert("chaining.");
Source:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With