Method chain
sample of method chain
by uedatakuya
JavaScript
function foo() {
var f1 = false;
var f2 = false;
var that = function() {
console.log("f1-"+f1);
console.log("f2-"+f2);
return that;
};
that.m1 = function() {
f1 = true;
return that;
};
that.m2 = function() {
f2 = true;
return that;
};
return that;
}
var foo1 = foo().m1().m2();
foo1();
var foo2 = foo().m1();
foo2();