Classes and Methods
Method Chains
Create an instance and use its method result immediately.
Method Chains
method_chain.js
const text = "trace";
class TextTool {
constructor(text) {
this.text = text;
}
upper() {
return this.text.toUpperCase();
}
}
const output = new TextTool(text).upper();
console.log("text=" + text);
console.log("output=" + output);
method-chain
For short-lived objects, creating an instance and using its method result in the next expression keeps the code compact while still showing the class behavior.