<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/tags/closure</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Thu, 23 May 2013 09:23:48 GMT</pubDate>
<item>
<title>(Groovy) Groovy way to replace regexp matches - alces</title>
<link>http://snipplr.com/view/70115/groovy-way-to-replace-regexp-matches/</link>
<description><![CDATA[ <p>Example of working with regexp sub-matches via Groovy way</p> ]]></description>
<pubDate>Wed, 27 Feb 2013 18:46:27 GMT</pubDate>
<guid>http://snipplr.com/view/70115/groovy-way-to-replace-regexp-matches/</guid>
</item>
<item>
<title>(Groovy) AntBuilder pseudo-targets - alces</title>
<link>http://snipplr.com/view/69816/antbuilder-pseudotargets/</link>
<description><![CDATA[ <p>Way to make ant-like pseudo-targets in groovy AntBuilder</p> ]]></description>
<pubDate>Wed, 06 Feb 2013 23:33:45 GMT</pubDate>
<guid>http://snipplr.com/view/69816/antbuilder-pseudotargets/</guid>
</item>
<item>
<title>(JavaScript) GeneratorModule: Array Creation Inspired by Python\'s List Comprehension - codernator</title>
<link>http://snipplr.com/view/69270/generatormodule-array-creation-inspired-by-pythons-list-comprehension/</link>
<description><![CDATA[ <p>The inspiration for this module comes from Python's list comprehension: [x for x in range(10)]. The idea is to replace a for-loop with something more condensed. However, since such syntax is completely foreign to Javascript, that operation looks more like: app.genList(app.rangeGenerator(0, 10)).

Requires ObjectBoilerPlateModule.

GeneratorModule comes with four "public" methods:

* getGeneratorModuleVersion - useful to test for existence of module.
* arrayGenerator - iterate over an array, optionally filtering items from the array with a predicate argument.
* rangeGenerator - iterate over a number sequence from min to max.
* genList - create an array using either an arrayGenerator or a rangeGenerator, optionally morphing elements from the generator into a new data type.

This is implemented using module pattern. To inject the functions into the global namespace, simply invoke the GeneratorModule method. Otherwise, the functions can be added to an existing object using GeneratorModule.call([object]).

Examples:

    function test() {
        "use strict";

        function reportNumber(number) {
            return number + " is " + (number % 2 === 0 ? "even" : "odd") + ".";
        }

        function reportLetter(letter) {
            return "The letter is " + letter + ".";
        }

        function isMultipleOf3(number) {
            return number % 3 === 0;
        }

        var app = {};
        ObjectBoilerPlateModule.call(app);
        GeneratorModule.call(app, app);
        console.log(app.toList(app.range(0, 10)));
        // [0,1,2,3,4,5,6,7,8,9]

        console.log(app.toList(reportNumber, app.range(0, 15), isMultipleOf3));
        // ["0 is even.", "3 is odd.", "6 is even.", "9 is odd.", "12 is even."]

        console.log(app.toList(app.inArray(["a", "d", 'q'])));
        // ["a", "d", "q"]

        console.log(app.toList(reportLetter, app.inArray(["a", "d", 'q']), function (x) { return x === "a"; }));
        // ["The letter is a."]
    }

Limitations/Considerations:

* Like Python generators, only 1 iteration will function - the generators do not come with a "reset" method.
* The ArrayGenerator objects hold reference to "list" passed in the constructor. If there is code between creating the generator and invoking it (say with genList), it is possible the contents of "list" will change. (This could be mitigated by having the ArrayGenerator constructor perform a deep copy "list"...)</p> ]]></description>
<pubDate>Thu, 27 Dec 2012 06:11:03 GMT</pubDate>
<guid>http://snipplr.com/view/69270/generatormodule-array-creation-inspired-by-pythons-list-comprehension/</guid>
</item>
<item>
<title>(JavaScript) Get DOM element via class and id selector, using Google Closure - cjcenizal</title>
<link>http://snipplr.com/view/62931/get-dom-element-via-class-and-id-selector-using-google-closure/</link>
<description><![CDATA[ <p>The Google Closure lets you get DOM elements with getElement( id ) and getElementByClass( class ).  This function combines the two to let you get elements similarly to the way jQuery does.  E.g. getElement( '#home .sidebar #links') returns the element with an id of 'links', within the element of class 'sidebar', within the element of id 'home'.</p> ]]></description>
<pubDate>Tue, 31 Jan 2012 15:00:26 GMT</pubDate>
<guid>http://snipplr.com/view/62931/get-dom-element-via-class-and-id-selector-using-google-closure/</guid>
</item>
<item>
<title>(JavaScript) Fresh JavaScript file (With namespaced, closured module pattern) - geekyjohn</title>
<link>http://snipplr.com/view/57085/fresh-javascript-file-with-namespaced-closured-module-pattern/</link>
<description><![CDATA[ <p>A JavaScript starter with a namespace and closure</p> ]]></description>
<pubDate>Sun, 24 Jul 2011 22:35:21 GMT</pubDate>
<guid>http://snipplr.com/view/57085/fresh-javascript-file-with-namespaced-closured-module-pattern/</guid>
</item>
<item>
<title>(PHP) Compress and Ofuscate static html pages using php and google closure - insane</title>
<link>http://snipplr.com/view/51800/compress-and-ofuscate-static-html-pages-using-php-and-google-closure/</link>
<description><![CDATA[ <p>It compress an static html page using php and output the response using document.write giving us a nice and ofuscated output check out your page source code after view it ;)</p> ]]></description>
<pubDate>Sat, 09 Apr 2011 05:37:48 GMT</pubDate>
<guid>http://snipplr.com/view/51800/compress-and-ofuscate-static-html-pages-using-php-and-google-closure/</guid>
</item>
<item>
<title>(JavaScript) using unobtrusive namespace - coprolit</title>
<link>http://snipplr.com/view/50920/using-unobtrusive-namespace/</link>
<description><![CDATA[ <p>Unobtrusive JavaScript should add as little as possible to the global object or global namespace of the environment in which it runs.
With following solution each module-writer's code is contained in private or in a unique namespace and cannot interfere with or intrude upon any other code at any time.</p> ]]></description>
<pubDate>Mon, 21 Mar 2011 23:57:37 GMT</pubDate>
<guid>http://snipplr.com/view/50920/using-unobtrusive-namespace/</guid>
</item>
<item>
<title>(JavaScript) Using params with setTimeOut - coprolit</title>
<link>http://snipplr.com/view/50827/using-params-with-settimeout/</link>
<description><![CDATA[ <p>With setTimeOut a reference to a function object cannot provide parameters for the scheduled execution of that function.
We can instead use a closure to provide parameters for the execution of a function prior to the execution of that function.</p> ]]></description>
<pubDate>Sat, 19 Mar 2011 01:38:02 GMT</pubDate>
<guid>http://snipplr.com/view/50827/using-params-with-settimeout/</guid>
</item>
<item>
<title>(JavaScript) Closure when using event handler - ichnoweb</title>
<link>http://snipplr.com/view/39976/closure-when-using-event-handler/</link>
<description><![CDATA[ <p>requires mootools</p> ]]></description>
<pubDate>Sat, 04 Sep 2010 01:12:40 GMT</pubDate>
<guid>http://snipplr.com/view/39976/closure-when-using-event-handler/</guid>
</item>
<item>
<title>(JavaScript) Settimeout with closure in for loop - mjsiemer</title>
<link>http://snipplr.com/view/39681/settimeout-with-closure-in-for-loop/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 30 Aug 2010 06:06:37 GMT</pubDate>
<guid>http://snipplr.com/view/39681/settimeout-with-closure-in-for-loop/</guid>
</item>
<item>
<title>(JavaScript) JavaScript Event Handler Closure - cfleschhut</title>
<link>http://snipplr.com/view/39058/javascript-event-handler-closure/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sat, 14 Aug 2010 01:17:14 GMT</pubDate>
<guid>http://snipplr.com/view/39058/javascript-event-handler-closure/</guid>
</item>
<item>
<title>(JavaScript) output   an array without for or while loop - hand4ever</title>
<link>http://snipplr.com/view/36669/output---an-array-without-for-or-while-loop/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sun, 04 Jul 2010 16:15:49 GMT</pubDate>
<guid>http://snipplr.com/view/36669/output---an-array-without-for-or-while-loop/</guid>
</item>
<item>
<title>(PHP) PHP anonymous functions and closures - jfoucher</title>
<link>http://snipplr.com/view/35567/php-anonymous-functions-and-closures/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 07 Jun 2010 14:18:20 GMT</pubDate>
<guid>http://snipplr.com/view/35567/php-anonymous-functions-and-closures/</guid>
</item>
<item>
<title>(Perl) Closure - johngh</title>
<link>http://snipplr.com/view/23658/closure/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 24 Nov 2009 07:43:00 GMT</pubDate>
<guid>http://snipplr.com/view/23658/closure/</guid>
</item>
<item>
<title>(JavaScript) closure - brianyang</title>
<link>http://snipplr.com/view/19138/closure/</link>
<description><![CDATA[ <p>When a function is defined in another function and it has access to the outer function's context even after the outer function returns.</p> ]]></description>
<pubDate>Tue, 01 Sep 2009 17:26:12 GMT</pubDate>
<guid>http://snipplr.com/view/19138/closure/</guid>
</item>
<item>
<title>(Groovy) Closure memoization in Groovy - narkisr</title>
<link>http://snipplr.com/view/18178/closure-memoization-in-groovy/</link>
<description><![CDATA[ <p>This example shows how its possible to cache (memoization) a Closure value, note that this works only for a single value per each delay method call (the Closure creates a closed scope in which its "state" is kept).</p> ]]></description>
<pubDate>Tue, 11 Aug 2009 11:15:43 GMT</pubDate>
<guid>http://snipplr.com/view/18178/closure-memoization-in-groovy/</guid>
</item>
<item>
<title>(JavaScript) Closure Example Relating to 'this' Execution Context - 1man</title>
<link>http://snipplr.com/view/5279/closure-example-relating-to-this-execution-context/</link>
<description><![CDATA[ <p>Example showing how using 'this' in a function depends on where 'this' is defined. From book jQuery in Action.</p> ]]></description>
<pubDate>Wed, 05 Mar 2008 17:32:40 GMT</pubDate>
<guid>http://snipplr.com/view/5279/closure-example-relating-to-this-execution-context/</guid>
</item>
<item>
<title>(JavaScript) Javascript Closure - 1man</title>
<link>http://snipplr.com/view/4247/javascript-closure/</link>
<description><![CDATA[ <p>Apologies if I haven't explained this to well, I'm still trying to get my head round closures.</p> ]]></description>
<pubDate>Sun, 02 Dec 2007 17:04:45 GMT</pubDate>
<guid>http://snipplr.com/view/4247/javascript-closure/</guid>
</item>
<item>
<title>(JavaScript) Unique ID generator without a global temp variable - noah</title>
<link>http://snipplr.com/view/2574/unique-id-generator-without-a-global-temp-variable/</link>
<description><![CDATA[ <p>This is cool and simple example of a closure.  It is from the Flanagan (Rhino) Javascript book, page 131 of the 5th edition.</p> ]]></description>
<pubDate>Tue, 01 May 2007 20:22:32 GMT</pubDate>
<guid>http://snipplr.com/view/2574/unique-id-generator-without-a-global-temp-variable/</guid>
</item>
<item>
<title>(Perl) Closure to change output - kkindoh</title>
<link>http://snipplr.com/view/281/closure-to-change-output/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sat, 08 Jul 2006 12:59:14 GMT</pubDate>
<guid>http://snipplr.com/view/281/closure-to-change-output/</guid>
</item>
</channel>
</rss>