<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MoMolog &#187; Javascript</title>
	<atom:link href="http://momolog.info/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://momolog.info</link>
	<description>MoMolog aus Berlin stellt sich vor. Projekte, Ideen, Referenzen.</description>
	<lastBuildDate>Sun, 18 Jul 2010 22:13:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MomoFlow</title>
		<link>http://momolog.info/2009/11/28/momoflow/</link>
		<comments>http://momolog.info/2009/11/28/momoflow/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 10:26:22 +0000</pubDate>
		<dc:creator>aljoscha</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://momolog.info/?p=219</guid>
		<description><![CDATA[Coverflow has become a de facto visualization standard for the presentation of collections of images, be it covers or portraits. There are a number of implementations for usage on web pages (e.g. this one) but the usable ones require Adobes Flash and thus won&#8217;t run on the iPhone. When looking for HTML5 canvas based implementations [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Cover_Flow">Coverflow</a> has become a  de facto visualization standard for the presentation of collections of images, be it covers or portraits.<br />
There are a number of implementations for usage on web pages (e.g. <a href="http://www.flashloaded.com/flashcomponents/photoflow/example1.html">this one</a>) but the usable ones require Adobes Flash and thus won&#8217;t run on the iPhone.</p>
<p>When looking for HTML5 canvas based implementations I found <a href="http://elmasse.gaver.nl/projects/Coverflow0.1/test.html">this promising implementation</a> based on the YUI library.<br />
Though workig, it has three major drawbacks: It is rather overengineered and difficult to tweak, it uses YUI (whereas I prefer the more lightweight jQuery) and it performs poorly with image sizes bigger than thumbnails.</p>
<p>After trying to change the code for a while I decided to do a reimplementation in jQuery. The result can be seen on the <a href="http://flow.momolog.info">MomoFlow demo page</a>. Here are two screenshots:</p>
<p><div id="attachment_229" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-229" title="MomoFlow I" src="http://momolog.info/wp-content/uploads/2009/11/Bildschirmfoto-2009-11-22-um-09.01.33-300x240.png" alt="CoverFlow using canvas and jQuery" width="300" height="240" /><p class="wp-caption-text">CoverFlow using canvas and jQuery</p></div></p>
<p><div id="attachment_226" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-226" title="MomoFlow II" src="http://momolog.info/wp-content/uploads/2009/11/Bildschirmfoto-2009-11-22-um-09.01.20-300x240.png" alt="Quicklook mode" width="300" height="240" /><p class="wp-caption-text">Quicklook mode</p></div></p>
<p>The used 3D transformation is superbly described on the <a href="http://yuiblog.com/blog/2008/06/23/slicing/">YUI blog</a> .</p>
<p>My implementation caches the rendered canvases per rendering angle. Further speed increments are made possible by adjusting the mesh width used for the slicing transformation depending on the achieved framerate.</p>
<p>The result performs beautifully in recent Safari, Chrome and Opera, decently on Firefox. It also works flawlessly on the iPhone. Keyboard control is coming soon.</p>
<p>I do still need help on IE, maybe the image composition is too demanding for <a href="http://excanvas.sourceforge.net/">ExplorerCanvas</a>? <br />
The code is available on github: <a href="http://github.com/momolog/momoflow">http://github.com/momolog/momoflow</a>.<br />
Comments and improvements are very much welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2009/11/28/momoflow/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Javascript function names</title>
		<link>http://momolog.info/2009/09/04/javascript-function-names/</link>
		<comments>http://momolog.info/2009/09/04/javascript-function-names/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 09:05:36 +0000</pubDate>
		<dc:creator>aljoscha</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://momolog.info/?p=149</guid>
		<description><![CDATA[Javascript allows naming and assigning functions at the same time like: var vname = function fname() {} The function name fname is available only inside the function as a local variable: var vname = function fname(){ &#160;&#160;console.log(typeof vname);&#160;&#160;// function &#160;&#160;console.log(typeof fname);&#160;&#160;// function } console.log(typeof vname);&#160;&#160;&#160;&#160;// function console.log(typeof fname);&#160;&#160;&#160;&#160;// undefined If we &#8220;redefine&#8221; this local variable [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript allows naming and assigning functions at the same time like:<br />
<pre>var vname = function fname() {}</pre><br />
The function name <code>fname</code> is available only <em>inside</em> the function as a local variable:<br />
<pre><pre>
var vname = function fname(){
&nbsp;&nbsp;console.log(typeof vname);&nbsp;&nbsp;// function
&nbsp;&nbsp;console.log(typeof fname);&nbsp;&nbsp;// function
}
console.log(typeof vname);&nbsp;&nbsp;&nbsp;&nbsp;// function
console.log(typeof fname);&nbsp;&nbsp;&nbsp;&nbsp;// undefined
</pre></pre><br />
If we &#8220;redefine&#8221; this local variable inside of the function, we get a strange effect:<br />
<pre><pre>
var vname = function fname(){
&nbsp;&nbsp;console.log(typeof vname);&nbsp;&nbsp;// function
&nbsp;&nbsp;console.log(typeof fname);&nbsp;&nbsp;// undefined !!!
&nbsp;&nbsp;var fname = 1;
&nbsp;&nbsp;console.log(typeof fname);&nbsp;&nbsp;// number
}
console.log(typeof vname);&nbsp;&nbsp;&nbsp;&nbsp;// function
console.log(typeof fname);&nbsp;&nbsp;&nbsp;&nbsp;// undefined
</pre></pre><br />
Obviously the interpreter  sees the variable declaration <code>var fname</code> </em>on entrance</em> into the function and does not provide the function variable at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2009/09/04/javascript-function-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototype Hash was killed</title>
		<link>http://momolog.info/2008/02/09/prototype-hash-was-killed/</link>
		<comments>http://momolog.info/2008/02/09/prototype-hash-was-killed/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 14:43:53 +0000</pubDate>
		<dc:creator>aljoscha</dc:creator>
				<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://momolog.info/2008/02/09/prototype-hash-was-killed/</guid>
		<description><![CDATA[In what they call a &#8220;backwards compatibility change&#8221; the prototype core developers have introduced some changes to the prototype Hash class. A little history: From version 1.5 the Hash class started behaving a bit differently because now the Enumerable methods where copied into the Hash prototype instead of into the instances, as before. That helped [...]]]></description>
			<content:encoded><![CDATA[<p>In what they call a &#8220;<a href="http://prototypejs.org/api/hash">backwards compatibility change</a>&#8221; the prototype core developers have introduced some changes to the prototype Hash class.<br />
A little history:<br />
From version 1.5 the Hash class started behaving a bit differently because now the Enumerable methods where copied into the Hash <strong>prototype</strong> instead of into the instances, as before. That helped minimize the memory footprint but introduced incompatibilities and removed the possibility to patch Enumerables methods because after patching Enumerable one would have to manually copy its methods into all &#8220;inheriting&#8221; classes again.<br />
To my understanding that is in conflict with the dynamic inheritance in prototype-based languages like javascript.<br />
See <a href="http://groups.google.com/group/prototype-core/browse_thread/thread/d6c5b3caa59f003d/524412167c69b4c8?lnk=gst&#038;q=hash#524412167c69b4c8">this thread</a> for more info.</p>
<p>Now with 1.6. things get worse. The Hash object is not an JS object with added functionality anymore, its a wrapper around one.<br />
The following code will work in 1.5.0.2 but not in 1.6:<br />
<pre><code>
test = $H({a: 1, b:2});
alert(test.a); // -&gt; 1 in version 1.5
</code></pre><br />
Instead, in prototype 1.6 you have to write <code>test.get(&#039;a&#039;)</code> to get to the property &#8220;a&#8221; of the underlying object. In case you need the whole object, there is always <code>test.toObject()</code> to the rescue. Bye bye, consise and short notation.</p>
<p>I feel the developers forgot what made prototype so wildly successfull: Its beautiful concept of enhancing the built in objects, not wrapping them.</p>
<p>I consider leaving the prototype world alltogether and will switch to <a href="http://mootools.net">mootools</a>. </p>
<p><a href="http://dev.rubyonrails.org/ticket/3592">Unlike prototype</a>, mootools returns a hash on filtering a hash.</p>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2008/02/09/prototype-hash-was-killed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testcase I</title>
		<link>http://momolog.info/2006/10/16/testcase-i/</link>
		<comments>http://momolog.info/2006/10/16/testcase-i/#comments</comments>
		<pubDate>Mon, 16 Oct 2006 09:42:53 +0000</pubDate>
		<dc:creator>aljoscha</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Prototype]]></category>

		<guid isPermaLink="false">http://momolog.info/2006/10/16/testcase-i/</guid>
		<description><![CDATA[These tests check that, with the prototype fix in place $H({fruit:&#34;apple&#34;, vegetable:&#34;cucumber&#34;}).reject( &#160;&#160;function(el) { return (el[1] == &#039;cucumber&#039;);} ) == $H({fruit:&#34;apple&#34;}) and $H({fruit:&#34;apple&#34;, vegetable:&#34;cucumber&#34;}).findAll( &#160;&#160;function(el) { return (el[1] == &#039;apple&#039;); } ) == $H({fruit:&#34;apple&#34;}) //]]></description>
			<content:encoded><![CDATA[<script src="/js/extlib/prototype/prototype-1.4.0-patched.js" type="text/javascript"></script>
<script src="/js/extlib/scriptaculous/unittest.js" type="text/javascript"></script>
<link rel="stylesheet" href="/js/extlib/scriptaculous/test.css" type="text/css" />

These tests check that, with the prototype fix in place 
<pre><pre>
$H({fruit:&quot;apple&quot;, vegetable:&quot;cucumber&quot;}).reject(
&nbsp;&nbsp;function(el) { return (el[1] == &#039;cucumber&#039;);}
) == $H({fruit:&quot;apple&quot;})
</pre></pre>
and 
<pre><pre>
$H({fruit:&quot;apple&quot;, vegetable:&quot;cucumber&quot;}).findAll(
&nbsp;&nbsp;function(el) { return (el[1] == &#039;apple&#039;); }
) == $H({fruit:&quot;apple&quot;}) 
</pre></pre>

<!-- Log output -->
<div id="testlog"> </div>

<!-- here go any elements you do the testing on -->

<!-- Tests -->
<script type="text/javascript" language="javascript">
// <![CDATA[
  new Test.Unit.Runner({
    
    setup: function(){with(this){
      this.given    = $H({fruit: "apple", vegetable: "cucumber"});
      this.expected = $H({fruit: "apple"});
    }},

    testReject: function(){ with(this) {
      var rejected  = this.given.reject(function(el) { return (el[1] == 'cucumber'); });
      assertEqual(this.expected.inspect(), rejected.inspect());
    }},

    testFind: function(){ with(this) {
      var found = this.given.findAll(function(el) { return (el[1] == 'apple'); });
      assertEqual(this.expected.inspect(), found.inspect());
    }}

  });



// ]]&gt;
</script>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2006/10/16/testcase-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing the Prototype Enumeration Mixin</title>
		<link>http://momolog.info/2006/10/14/prototype-enumeration/</link>
		<comments>http://momolog.info/2006/10/14/prototype-enumeration/#comments</comments>
		<pubDate>Sat, 14 Oct 2006 11:42:56 +0000</pubDate>
		<dc:creator>aljoscha</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[The following article describes ticket #3592 in the RoR Trac and explains a proposed solution. Prototypes Enumerable mixin class does not properly respect the mixees internal format. For example the reject and findAll methods, operating on Hashes, return Arrays instead of Hashes. var a = $H({a:1, b:2, c:1, d:3}); document.writeln(a.inspect().escapeHTML()); =&#62;#&#60;Hash:{&#039;a&#039;: 1, &#039;b&#039;: 2, &#039;c&#039;: [...]]]></description>
			<content:encoded><![CDATA[<p>The following article describes <a href="http://dev.rubyonrails.org/ticket/3592">ticket #3592</a> in the RoR Trac and explains a proposed solution.</p>
<p>Prototypes Enumerable mixin class does not properly respect the mixees internal format. For example the <code>reject</code> and <code>findAll</code> methods, operating on Hashes, return Arrays instead of Hashes.<br />
<pre><pre>
var a = $H({a:1, b:2, c:1, d:3}); 
document.writeln(a.inspect().escapeHTML());

=&gt;#&lt;Hash:{&#039;a&#039;: 1, &#039;b&#039;: 2, &#039;c&#039;: 1, &#039;d&#039;: 3}&gt;

var b = a.reject(function(val){ return (val[1]==1) });
document.writeln(b.inspect().escapeHTML());

=&gt; [[&#039;b&#039;, 2], [&#039;d&#039;, 3]]&nbsp;&nbsp; // !!! should be hash

var c = b.findAll(function(val){ return (val[0]==&#039;d&#039;) });
document.writeln(c.inspect().escapeHTML());

=&gt; [[&#039;b&#039;, 2], [&#039;d&#039;, 3]]&nbsp;&nbsp; // !!! should be hash
</pre></pre></p>
<p>In Ruby (from which the inspiration for the Enumerable Mixin stems), the reject method does return a hash, not an array, when operating on an hash:<br />
<pre><pre> 
irb(main):001:0&gt; a={:a =&gt; 1, :b =&gt; 2, :c =&gt; 1, :d =&gt; 3}&nbsp;&nbsp;

=&gt; {:b=&gt;2, :c=&gt;1, :a=&gt;1, :d=&gt;3}&nbsp;&nbsp;

irb(main):002:0&gt; b=a.reject{|k,v| v==1}

=&gt; {:b=&gt;2, :d=&gt;3} 
</pre></pre><br />
The patch requires all classes that want to mixin Enumerable to define two more methods similar to <code>_each</code>:<br />
<code>_new</code>, which returns an empty object of that class and<br />
<code>_add</code>, that adds an element. Enumerable mixin thus needs to make no more assumptions about the internal structure of its mixee class.</p>
<p>After the fix the methods return correctly:<br />
<pre><pre>
=&gt; #&lt;Hash:{&#039;b&#039;: 2, &#039;d&#039;: 3}&gt;
</pre></pre> </p>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2006/10/14/prototype-enumeration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
