Chaining Functions using "This"

Run Settings
LanguageJavaScript
Language Version
Run Command
var MathObject = function (initialValue) { this.value = initialValue || 0; this.add = function (num) { this.value += num; return this; }; this.sub = function (num) { this.value -= num; return this; }; }; var myMath = new MathObject(10); console.log(myMath.value); myMath.add(5); console.log(myMath.value); myMath.add(5).add(6).sub(20); console.log(myMath.value);
Editor Settings
Theme
Key bindings
Full width
Lines