Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created August 28, 2008 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save beastaugh/7727 to your computer and use it in GitHub Desktop.
Save beastaugh/7727 to your computer and use it in GitHub Desktop.
The K Combinator in JavaScript
/**
* 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