<?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; Prototype</title>
	<atom:link href="http://momolog.info/category/javascript/prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://momolog.info</link>
	<description>MoMolog aus Berlin stellt sich vor. Projekte, Ideen, Referenzen.</description>
	<lastBuildDate>Sat, 21 Jan 2012 12:35:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<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 />
<code><br />
test = $H({a: 1, b:2});<br />
alert(test.a); // -> 1 in version 1.5<br />
</code><br />
Instead, in prototype 1.6 you have to write <code>test.get('a')</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:"apple", vegetable:"cucumber"}).reject( function(el) { return (el[1] == 'cucumber');} ) == $H({fruit:"apple"}) and $H({fruit:"apple", vegetable:"cucumber"}).findAll( function(el) { return (el[1] == 'apple'); } ) == $H({fruit:"apple"}) //]]></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>
$H({fruit:"apple", vegetable:"cucumber"}).reject(
  function(el) { return (el[1] == 'cucumber');}
) == $H({fruit:"apple"})
</pre>
and 
<pre>
$H({fruit:"apple", vegetable:"cucumber"}).findAll(
  function(el) { return (el[1] == 'apple'); }
) == $H({fruit:"apple"}) 
</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()); =># var b = a.reject(function(val){ [...]]]></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.</p>
<pre>
var a = $H({a:1, b:2, c:1, d:3});
document.writeln(a.inspect().escapeHTML());

=>#<Hash:{'a': 1, 'b': 2, 'c': 1, 'd': 3}>

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

=> [['b', 2], ['d', 3]]   // !!! should be hash

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

=> [['b', 2], ['d', 3]]   // !!! should be hash
</pre>
<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:  </p>
<pre>
irb(main):001:0> a={:a => 1, :b => 2, :c => 1, :d => 3}  

=> {:b=>2, :c=>1, :a=>1, :d=>3}  

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

=> {:b=>2, :d=>3}
</pre>
<p>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:</p>
<pre>
=> #<Hash:{'b': 2, 'd': 3}>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://momolog.info/2006/10/14/prototype-enumeration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

