-
-
Save CodeOfficer/454392 to your computer and use it in GitHub Desktop.
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
/** | |
* An implementation of the K Combinator. | |
* http://wiki.tcl.tk/1923 | |
* | |
* Copied from Mikael Brockman's code in Ruby on Rails' ActiveSupport library. | |
* http://weblog.jamisbuck.org/2006/10/27/mining-activesupport-object-returning | |
*/ | |
function returning(value, block, context) { | |
block.call(context || null, value); | |
return value; | |
}; | |
(function test_returning() { | |
var test = returning({}, function(obj) { | |
obj.cool = "Brilliant!"; | |
obj.wow = "Amazing!" | |
}); | |
print(test.cool); | |
print(test.wow); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment