Tech Tip: Chaining user class functions
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: August 21, 2023
With the introduction of the return keyword in v20, now any user class function can be written to be chain-able. Simply return This at the end of the function. For example, given the class below:
// Class: Phrase Class constructor($phrase : Text) This.phrase:=$phrase Function question() This.phrase+="?" return This Function exclaim() This.phrase+="!" return This |
Its question() and exclaim() functions can be chained, like below:
// simple use case $newPhrase:=cs.Phrase.new("Hello world") $newPhrase.question().exclaim().question() $myPhrase:=$newPhrase.phrase // "Hello world?!?" |