Skip to content

Instantly share code, notes, and snippets.

@russplaysguitar
Created August 4, 2012 21:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russplaysguitar/3259915 to your computer and use it in GitHub Desktop.
Save russplaysguitar/3259915 to your computer and use it in GitHub Desktop.
Turn a Coldfusion Struct into an "object" using _.bindAll()
/*
This is an example of one way to use _.bindAll from the Underscore.cfc library: http://russplaysguitar.github.com/UnderscoreCF/#bindAll
Normally, you wouldn't be able to access other keys in the same struct using "this", but _.bindAll() lets us!
*/
_ = new Underscore();
exampleStruct = {
greeting: 'Hello, World!',
sayHi: function () {// note: in Railo 4, you must pass in "this" as an argument
writeDump(this.greeting);
}
};
_.bindAll(exampleStruct);
exampleStruct.sayHi();// => "Hello, World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment