Search

Top Ten List

Of all my ramblings, people seem to find the following the most interesting:
  1. Pimp My Fields
  2. Using the WebBrowser control to view attachments inline
  3. Purty charts in Domino
  4. My approach to DbLookup and DbColumn in Javascript
  5. Mind Map of Database Design
  6. Design Catalog - version control for Domino
  7. Workaround for LotusScript event binding
  8. Clickable URL's in Notes view columns
  9. Every time you use window.open, God kills a kitten
  10. Create, edit, and delete without agents via AJAX

« Changing read-only database settings with DXL | Main| New toy: Belkin Wi-Fi Skype phone »

Chaining methods in LotusScript

Category show-n-tell thursday
One characteristic now common to several popular Javascript libraries (such as Mootools, jQuery, and the newly updated Prototype) is the ability to chain methods: that is, to do several things to or with an object in a single line of code. For example:

Clown.makeBalloonAnimal().rideUnicycle().frightenSmallChildren();

This appeals to many of us because, well, we're lazy. That's not a bad thing - the point of code is to make some task or process easier for users; so why not structure code in a way that makes it easier to reference that code later on?

Anyhow, what makes this possible in Javascript is that all methods are functions. Even what LotusScripters would consider a Sub. Which means that all methods have a return value, even if none is explicitly specified. A chainable method, then, is simply a function that returns an object (typically the instance containing the method).

In LotusScript, this is easily accomplished by making each Sub a Function instead and using the keyword Me:

Public Class Clown Public Function makeBalloonAnimal() As Clown 'Method statements Set makeBalloonAnimal = Me End Function Public Function rideUnicycle() As Clown 'Method statements Set rideUnicycle = Me End Function Public Function frightenSmallChildren() As Clown 'Method statements Set frightenSmallChildren = Me End Function End Class

All methods of the class are now chainable:
Sub Initialize Dim Bozo As Clown Set Bozo = New Clown() Call Bozo.makeBalloonAnimal().rideUnicycle().frightenSmallChildren() End Sub

Comments

Gravatar Image1 - Concise and thoughtful - Amazing!
Chapeau bas! Tim

Gravatar Image2 - That is a VERY interesting technique. Thanks for the tip!

Contact Me

Hire Me

Elsewhere

What the Quote?

"When driving in Jersey, you need to drive confident, so everyone else drives scared."

Steven Rodgers

"If you love somebody, set them free."

Linus Torvalds

"If I can get the foot thing out of my head, then I can eat my potato."

Laura Tripcony

"I was talking to your boss last night, and he told me, 'I have some really bright people... I'm just not so sure that they're sane'."

Mary Beth Raven

"Talking about sports at Starbucks is just like talking about a Yarn Barn event at ESPN Zone."

Mike Koenig

Apparel

Lotus Rocks

I write the code that makes the young girls cry

Current Terror Alert Level

Assorted Linkage

ClustrMap