Changeset 815

Show
Ignore:
Timestamp:
04/28/06 15:43:44 (2 years ago)
Author:
bob@redivi.com
Message:

nix predicate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • presentations/2006/ajax_experience/slides.html

    r814 r815  
    419419<h1>toString Ambiguity</h1> 
    420420<ul class="simple"> 
    421 <li>[1].toString() === &quot;1&quot;</li> 
    422 <li>(1).toString() === &quot;1&quot;</li> 
    423 <li>&quot;1&quot;.toString() === &quot;1&quot;</li> 
     421<li>[1].toString() === '1'</li> 
     422<li>(1).toString() === '1'</li> 
     423<li>'1'.toString() === '1'</li> 
    424424</ul> 
    425425</div> 
     
    452452<ul class="simple"> 
    453453<li>Most JavaScript comparisons based on toString</li> 
    454 <li><!-- but [1] == [1] is false! --> 
    455 </li> 
     454<li>[1] == [1] is false!</li> 
    456455<li>compare(a, b) provides consistent results</li> 
    457456<li>Extensible</li> 
     
    479478<dd>unique identifier for your adapter</dd> 
    480479<dt>check:</dt> 
    481 <dd>predicate, should wrap be called?</dd> 
     480<dd>should wrap be called?</dd> 
    482481<dt>wrap:</dt> 
    483482<dd>performs the operation</dd> 
     
    489488<pre class="literal-block"> 
    490489function isDOMNode(node) { 
    491     return typeof(node.nodeType) == &quot;number&quot;
     490    return typeof(node.nodeType) == 'number'
    492491} 
    493492 
     
    496495} 
    497496 
    498 registerComparator(&quot;compareDOM&quot;
     497registerComparator('compareDOM'
    499498    isDOMNode, compareDOMNode); 
    500499</pre> 
     
    504503<ul class="simple"> 
    505504<li>Easily build URL query strings</li> 
    506 <li>queryString([&quot;foo&quot;, &quot;bar&quot;], [1, 2]) == &quot;foo=1&amp;bar=2&quot;</li> 
    507 <li>queryString({foo: 1, bar: 2}) == &quot;foo=1&amp;bar=2&quot;</li> 
     505<li>queryString(['foo', 'bar'], [1, 2]) == 'foo=1&amp;bar=2'</li> 
     506<li>queryString({foo: 1, bar: 2}) == 'foo=1&amp;bar=2'</li> 
    508507</ul> 
    509508</div> 
     
    511510<h1>queryString and DOM</h1> 
    512511<ul> 
    513 <li><p class="first">queryString(&quot;formNode&quot;) == &quot;foo=1&amp;bar=2&quot;, given:</p> 
     512<li><p class="first">queryString('formNode') == 'foo=1&amp;bar=2', given:</p> 
    514513<pre class="literal-block"> 
    515514&lt;form id=&quot;formNode&quot;&gt; 
     
    582581<h1>Higher-order Array</h1> 
    583582<dl class="docutils"> 
    584 <dt>filter(predicate, lst):</dt> 
    585 <dd>Array where predicate(lst[n])</dd> 
     583<dt>filter(func, lst):</dt> 
     584<dd>Array where funcn(lst[n])</dd> 
    586585<dt>map(func, lst):</dt> 
    587586<dd>[func(lst[0]), ...]</dd> 
     
    692691<li>JavaScript has no sprintf</li> 
    693692<li>Thousands separators help readability</li> 
    694 <li>Java's Number Format Pattern Syntax</li> 
     693<li>Java's NumberFormat pattern syntax</li> 
    695694</ul> 
    696695</div> 
     
    717716<p>Currency:</p> 
    718717<pre class="literal-block"> 
    719 &gt;&gt;&gt; money = numberFormatter(&quot;$###,###.##&quot;
     718&gt;&gt;&gt; money = numberFormatter('$###,###.##'
    720719&gt;&gt;&gt; money(1234567.89) 
    721720&quot;$1,234,567.89&quot; 
     
    726725<p>Percent:</p> 
    727726<pre class="literal-block"> 
    728 &gt;&gt;&gt; percent = numberFormatter(&quot;###,###%&quot;
     727&gt;&gt;&gt; percent = numberFormatter('###,###%'
    729728&gt;&gt;&gt; percent(123.45) 
    730729&quot;12,345%&quot; 
     
    810809<p>A simple list:</p> 
    811810<pre class="literal-block"> 
    812 var node = createDOM(&quot;ul&quot;, null, 
    813     createDOM(&quot;li&quot;, null, &quot;first&quot;), 
    814     createDOM(&quot;li&quot;, null, &quot;second&quot;)); 
     811var node = createDOM('ul', null, 
     812    createDOM('li', null, 'first'), 
     813    createDOM('li', null, 'second')); 
    815814</pre> 
    816815<p>Renders as:</p> 
     
    824823<pre class="literal-block"> 
    825824var node = UL(null, 
    826     LI(&quot;first&quot;), 
    827     LI(&quot;second&quot;)); 
     825    LI('first'), 
     826    LI('second')); 
    828827</pre> 
    829828</div> 
     
    832831<p>Functional style handy for DOM creation:</p> 
    833832<pre class="literal-block"> 
    834 var items = [&quot;first&quot;, &quot;second&quot;]; 
     833var items = ['first', 'second']; 
    835834var node = UL(null, map(LI, items)); 
    836835</pre> 
     
    840839<p>First parameter is either an object (attributes), or a string (text node):</p> 
    841840<pre class="literal-block"> 
    842 var classes = repeat({&quot;class&quot;: &quot;itemclass&quot;}); 
    843  
    844 var items = [&quot;first&quot;, &quot;second&quot;]; 
    845  
    846 var node = UL({&quot;class&quot;: &quot;listclass&quot;}, 
     841var classes = repeat({'class': 'itemclass'}); 
     842 
     843var items = ['first', 'second']; 
     844 
     845var node = UL({'class': 'listclass'}, 
    847846    map(LI, classes, items)); 
    848847</pre> 
     
    853852<pre class="literal-block"> 
    854853var classes = cycle( 
    855     {&quot;class&quot;: &quot;even&quot;}, 
    856     {&quot;class&quot;: &quot;odd&quot;}); 
    857  
    858 var items = [&quot;first&quot;, &quot;second&quot;]; 
     854    {'class': 'even'}, 
     855    {'class': 'odd'}); 
     856 
     857var items = ['first', 'second']; 
    859858 
    860859var node = UL(null, 
     
    887886<p>JavaScript:</p> 
    888887<pre class="literal-block"> 
    889 &gt;&gt;&gt; scrapeText(&quot;scrape_me&quot;); 
     888&gt;&gt;&gt; scrapeText('scrape_me'); 
    890889&quot;text is here&quot; 
    891890</pre> 
     
    902901<p>JavaScript:</p> 
    903902<pre class="literal-block"> 
    904 &gt;&gt;&gt; formContents(&quot;formNode&quot;
     903&gt;&gt;&gt; formContents('formNode'
    905904[[&quot;foo&quot;, &quot;bar&quot;], [&quot;1&quot;, &quot;2&quot;]] 
    906905</pre> 
     
    957956</dl> 
    958957<ul class="simple"> 
    959 <li>&quot;rgb(...)&quot;</li> 
    960 <li>&quot;hsl(...)&quot;</li> 
    961 <li>&quot;#RRGGBB&quot;</li> 
    962 <li>&quot;blue&quot;</li> 
     958<li>'rgb(...)'</li> 
     959<li>'hsl(...)'</li> 
     960<li>'#RRGGBB'</li> 
     961<li>'blue'</li> 
    963962</ul> 
    964963</div> 
     
    10721071function gotDocument(json) { /* ... */ } 
    10731072function delay(res) { return wait(2.0, res); } 
    1074 var d = loadJSONDoc(&quot;example.json&quot;); 
     1073var d = loadJSONDoc('example.json'); 
    10751074d.addCallback(delay); 
    10761075d.addCallback(gotDocument); 
     
    11011100function myClick(e) { 
    11021101    var mouse = e.mouse(); 
    1103     log(&quot;page coordinates: &quot; + mouse.page); 
    1104     log(&quot;client coordinates: &quot; + mouse.client); 
     1102    log('page coordinates: ' + mouse.page); 
     1103    log('client coordinates: ' + mouse.client); 
    11051104} 
    1106 connect(&quot;element_id&quot;, &quot;onclick&quot;, myClick); 
     1105connect('element_id', 'onclick', myClick); 
    11071106</pre> 
    11081107</div> 
  • presentations/2006/ajax_experience/slides.txt

    r814 r815  
    8282================== 
    8383 
    84 * [1].toString() === "1" 
    85 * (1).toString() === "1" 
    86 * "1".toString() === "1" 
     84* [1].toString() === '1' 
     85* (1).toString() === '1' 
     86* '1'.toString() === '1' 
    8787 
    8888 
     
    111111 
    112112* Most JavaScript comparisons based on toString 
    113 * .. but [1] == [1] is false! 
     113* [1] == [1] is false! 
    114114* compare(a, b) provides consistent results 
    115115* Extensible 
     
    138138 
    139139check: 
    140     predicate, should wrap be called? 
     140    should wrap be called? 
    141141 
    142142wrap: 
     
    150150 
    151151    function isDOMNode(node) { 
    152         return typeof(node.nodeType) == "number"
     152        return typeof(node.nodeType) == 'number'
    153153    } 
    154154 
     
    157157    } 
    158158 
    159     registerComparator("compareDOM"
     159    registerComparator('compareDOM'
    160160        isDOMNode, compareDOMNode); 
    161161 
     
    165165 
    166166* Easily build URL query strings 
    167 * queryString(["foo", "bar"], [1, 2]) == "foo=1&bar=2" 
    168 * queryString({foo: 1, bar: 2}) == "foo=1&bar=2" 
     167* queryString(['foo', 'bar'], [1, 2]) == 'foo=1&bar=2' 
     168* queryString({foo: 1, bar: 2}) == 'foo=1&bar=2' 
    169169 
    170170 
     
    172172=================== 
    173173 
    174 * queryString("formNode") == "foo=1&bar=2", given:: 
     174* queryString('formNode') == 'foo=1&bar=2', given:: 
    175175 
    176176    <form id="formNode"> 
     
    253253================== 
    254254 
    255 filter(predicate, lst): 
    256     Array where predicate(lst[n]) 
     255filter(func, lst): 
     256    Array where funcn(lst[n]) 
    257257 
    258258map(func, lst): 
     
    378378* JavaScript has no sprintf 
    379379* Thousands separators help readability 
    380 * Java's Number Format Pattern Syntax 
     380* Java's NumberFormat pattern syntax 
    381381 
    382382 
     
    406406Currency:: 
    407407 
    408     >>> money = numberFormatter("$###,###.##"
     408    >>> money = numberFormatter('$###,###.##'
    409409    >>> money(1234567.89) 
    410410    "$1,234,567.89" 
     
    416416Percent:: 
    417417 
    418     >>> percent = numberFormatter("###,###%"
     418    >>> percent = numberFormatter('###,###%'
    419419    >>> percent(123.45) 
    420420    "12,345%" 
     
    512512A simple list:: 
    513513 
    514     var node = createDOM("ul", null, 
    515         createDOM("li", null, "first"), 
    516         createDOM("li", null, "second")); 
     514    var node = createDOM('ul', null, 
     515        createDOM('li', null, 'first'), 
     516        createDOM('li', null, 'second')); 
    517517 
    518518Renders as:: 
     
    527527 
    528528    var node = UL(null, 
    529         LI("first"), 
    530         LI("second")); 
     529        LI('first'), 
     530        LI('second')); 
    531531 
    532532 
     
    536536Functional style handy for DOM creation:: 
    537537 
    538     var items = ["first", "second"]; 
     538    var items = ['first', 'second']; 
    539539    var node = UL(null, map(LI, items)); 
    540540 
     
    545545First parameter is either an object (attributes), or a string (text node):: 
    546546 
    547     var classes = repeat({"class": "itemclass"}); 
    548  
    549     var items = ["first", "second"]; 
    550  
    551     var node = UL({"class": "listclass"}, 
     547    var classes = repeat({'class': 'itemclass'}); 
     548 
     549    var items = ['first', 'second']; 
     550 
     551    var node = UL({'class': 'listclass'}, 
    552552        map(LI, classes, items)); 
    553553 
     
    559559 
    560560    var classes = cycle( 
    561         {"class": "even"}, 
    562         {"class": "odd"}); 
    563  
    564     var items = ["first", "second"]; 
     561        {'class': 'even'}, 
     562        {'class': 'odd'}); 
     563 
     564    var items = ['first', 'second']; 
    565565 
    566566    var node = UL(null, 
     
    591591JavaScript:: 
    592592 
    593     >>> scrapeText("scrape_me"); 
     593    >>> scrapeText('scrape_me'); 
    594594    "text is here" 
    595595 
     
    607607JavaScript:: 
    608608 
    609     >>> formContents("formNode"
     609    >>> formContents('formNode'
    610610    [["foo", "bar"], ["1", "2"]] 
    611611 
     
    664664    Color from any valid CSS color description 
    665665 
    666 - "rgb(...)" 
    667 - "hsl(...)" 
    668 - "#RRGGBB" 
    669 - "blue" 
     666- 'rgb(...)' 
     667- 'hsl(...)' 
     668- '#RRGGBB' 
     669- 'blue' 
    670670 
    671671 
     
    790790    function gotDocument(json) { /* ... */ } 
    791791    function delay(res) { return wait(2.0, res); } 
    792     var d = loadJSONDoc("example.json"); 
     792    var d = loadJSONDoc('example.json'); 
    793793    d.addCallback(delay); 
    794794    d.addCallback(gotDocument); 
     
    820820    function myClick(e) { 
    821821        var mouse = e.mouse(); 
    822         log("page coordinates: " + mouse.page); 
    823         log("client coordinates: " + mouse.client); 
     822        log('page coordinates: ' + mouse.page); 
     823        log('client coordinates: ' + mouse.client); 
    824824    } 
    825     connect("element_id", "onclick", myClick); 
     825    connect('element_id', 'onclick', myClick); 
    826826 
    827827