With Chaining Pattern you can call object methods one after the others without assigning the result to other variables or break them in multiple statement or lines.
For example:
myobj.func1().func2(1,2,3).func3('fsnjk');
This pattern is only useful when object functions do not have to special return so, this pattern can implemented by returning this in each object function.
For example:
var myelm={
hide: function(second){
//code for hiding
return this;
},
fadeIn: function(second){
//code for fading
return this;
}
};
myelm.hide(1).fadeIn(2);
For example:
myobj.func1().func2(1,2,3).func3('fsnjk');
This pattern is only useful when object functions do not have to special return so, this pattern can implemented by returning this in each object function.
For example:
var myelm={
hide: function(second){
//code for hiding
return this;
},
fadeIn: function(second){
//code for fading
return this;
}
};
myelm.hide(1).fadeIn(2);
Comments
Post a Comment