Created
August 4, 2012 21:03
-
-
Save russplaysguitar/3259915 to your computer and use it in GitHub Desktop.
Turn a Coldfusion Struct into an "object" using _.bindAll()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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