Chaining JS functions in namespace #1
by toubia95
CSS
/*
http://stackoverflow.com/questions/603499/javascript-object-method-chaining-useful?rq=1
*/
JavaScript
var truck = function() {
this.turnLeft = function {
// turn left
return this;
}
this.turnRight = function {
// turn right
return this;
}
this.goReallyFast = function {
// go fast!
return this;
}
};
// My get-away plan
var myTruck = new truck();
myTruck.turnLeft().turnRight().goReallyFast();