Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created August 28, 2008 14:05
Show Gist options
  • Select an option

  • Save beastaugh/7727 to your computer and use it in GitHub Desktop.

Select an option

Save beastaugh/7727 to your computer and use it in GitHub Desktop.

Revisions

  1. beastaugh revised this gist Aug 28, 2008. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions kcombinator.js
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,9 @@
    * 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(object, block) {
    block(object);
    return object;
    function returning(value, block, context) {
    block.call(context || null, value);
    return value;
    };

    (function test_returning() {
    @@ -19,4 +19,3 @@ function returning(object, block) {
    print(test.cool);
    print(test.wow);
    })();

  2. beastaugh created this gist Aug 28, 2008.
    22 changes: 22 additions & 0 deletions kcombinator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /**
    * 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(object, block) {
    block(object);
    return object;
    };

    (function test_returning() {
    var test = returning({}, function(obj) {
    obj.cool = "Brilliant!";
    obj.wow = "Amazing!"
    });

    print(test.cool);
    print(test.wow);
    })();