<?xml version="1.0" encoding="UTF-8"?>
<!-- name="generator" content="blojsom v3.2" -->
<rdf:RDF xmlns:wfw="http://wellformedweb.org/CommentAPI/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns="http://purl.org/rss/1.0/">

	<channel rdf:about="http://dhtmlkitchen.com/news/default">
		<title>DHTML Kitchen News</title>
		<link>http://dhtmlkitchen.com/news/default/</link>
		<description>Front End Web Development</description>
		<dc:publisher>Garrett Smith</dc:publisher>
		<dc:creator>dhtmkitchen@gmail.com</dc:creator>
		<dc:date>2009-05-29T00:06:00-05:00</dc:date>
		<dc:language>en</dc:language>

        <items>
        <rdf:Seq>
                                <rdf:li rdf:resource="http://dhtmlkitchen.com/news/default/2009/05/29/Myopia-and-the-Opera-10-User-Agent-String" />
                                <rdf:li rdf:resource="http://dhtmlkitchen.com/news/default/2008/09/11/Function-prototype-bind" />
                                <rdf:li rdf:resource="http://dhtmlkitchen.com/news/default/2008/07/04/Find-Element-Position" />
                                <rdf:li rdf:resource="http://dhtmlkitchen.com/news/default/2008/06/17/Prototype-js-A-Review" />
                                <rdf:li rdf:resource="http://dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok" />
                </rdf:Seq>
        </items>
    </channel>

            <item rdf:about="http://dhtmlkitchen.com/news/default/2009/05/29/Myopia-and-the-Opera-10-User-Agent-String">
	    <title>Myopia and the Opera 10 User Agent String</title>
	    <link>http://dhtmlkitchen.com/news/default/2009/05/29/Myopia-and-the-Opera-10-User-Agent-String</link>
        <description>&lt;p&gt;
Opera has conceived a &lt;a href=&quot;http://dev.opera.com/articles/view/opera-ua-string-changes/&quot;&gt;silly tactic&lt;/a&gt; planned for Opera 10 user-agent string.          
&lt;/p&gt;

&lt;p&gt;The problem is that there are scripts that expect the browser major version to single-digit and will fail if it is not.
&lt;/p&gt;

&lt;p&gt;
 Since &quot;10&quot; not a single digit, these scripts fail.
&lt;/p&gt;

&lt;p&gt;Opera has mitigated that problem by changing the user-agent to 9.80 and publishing the following warning:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
Browser sniffing — unless you’re writing a web stats application — is 
 always a bad idea. It’s a misguided attempt to send different content  
 to different user agents. This is never scalable — you can’t change 
 every website you’ve ever made every time a new browser version comes 
 out. It is also not future-proof, as highlighted by this article.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Ineffectual and meaningless little blurb there. Those badly written sites that used (poor) browser detection will not break from Opera. Opera spoofing their own user-agent string helps reaffirm the misconception that the authors&#39; browser detection worked. Posting up a little warning that not everyone will read does not make an example. 
&lt;/p&gt;

&lt;p&gt;
The blurb states that Browser detection is used &quot;to send different content to different user agents&quot;. Not always true. In fact, browser detection is more often used on the client to work around an perceived incompatibility. Since Opera is wrong on that count, it makes the blurb seem even less relevant, as an author who read it might still try to justify or rationalize his approach by saying &quot;but that&#39;s not why I used browser detection.&quot;
&lt;/p&gt;

&lt;p&gt;
Browser detection scripts cause forwards-compatibility and maintenance problems. However, to not be able to parse out a number is not only not smart, it shows very poor coding skill. 
&lt;/p&gt;
&lt;p&gt;
Opera states that version 11 will have &quot;11&quot; in the user-agent string.
&lt;/p&gt;

&lt;p&gt;
My opinion is somewhat in line with &lt;a href=&quot;http://blog.360.yahoo.com/blog-TBPekxc1dLNy5DOloPfzVvFIVOWMB0li?p=1008
&quot;&gt;Doug&#39;s&lt;/a&gt; on this one (&lt;small&gt;that Yahoo 360 URL is an awful URL&lt;/small&gt;). 
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
 If you are a developer, check your code. It really isn&#39;t 
  hard to do this stuff correctly. It really isn&#39;t. 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
 Where I disagree with Doug is &lt;cite&gt;&quot;Opera has been forced to lie.&quot;&lt;/cite&gt;
&lt;/p&gt;
&lt;p&gt;
 Opera developers made a &lt;em&gt;decision&lt;/em&gt; to lie, as explained by Opera. They were not forced. 
&lt;/p&gt;
&lt;p&gt;
 An alternative to that choice is for Opera to not cater to badly authored pages and simply let them break.
&lt;/p&gt;
&lt;p&gt;
Breaking sites is bad in the short term because it renders pages unusable. However, it is good in the larger scheme of the web in the long run. By driving home a hard lesson, Opera could teach developers to not use browser detection by providing an historical lesson.
&lt;/p&gt;

&lt;p&gt;
  The first sensible opinion on the matter was &lt;a href=&quot;http://my.opera.com/hallvors/blog/2008/12/19/10-is-the-one&quot;&gt;Hallvord&#39;s post from December, 2008.&lt;/a&gt;, where he pointed out that Bank of America and Live.com failed in Opera 10. The entry describes the reason: Faulty parsing of the &lt;code&gt;User-Agent&lt;/code&gt; string, and redirecting to the &quot;not supported page&quot;. 
&lt;/p&gt;
&lt;blockquote cite=&quot;http://my.opera.com/hallvors/blog/2008/12/19/10-is-the-one&quot;&gt;
&lt;p&gt;
You&#39;d think that with the intense development Microsoft has been lavishing on live.com they would have found somebody capable of writing a usable browser sniffer (or ideally a person clever enough to say &quot;wait, we don&#39;t really need one - what if we just use feature detection instead?&quot;). Think again..
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
 Of course, Microsoft has been advocating detection &quot;best practices&quot; for years, despite well reasoned arguments to stop doing that (&lt;a href=&quot;http://blogs.msdn.com/ie/archive/2009/01/09/the-internet-explorer-8-user-agent-string-updated-edition.aspx#9305124&quot;&gt;G. Talbot&lt;/a&gt;, &lt;a href=&quot;http://blogs.msdn.com/ie/archive/2009/01/09/the-internet-explorer-8-user-agent-string-updated-edition.aspx#9305799&quot;&gt;T. Zijdel&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;
 Opera should be less myopic and stop worrying about breaking badly authored sites. Web developers should be less myopic, and build maintainable, forwards-compatible solutions. 
&lt;/p&gt;
</description>
	    <dc:date>2009-05-29T00:06:00-05:00</dc:date>
	        </item>
            <item rdf:about="http://dhtmlkitchen.com/news/default/2008/09/11/Function-prototype-bind">
	    <title>Function.prototype.bind</title>
	    <link>http://dhtmlkitchen.com/news/default/2008/09/11/Function-prototype-bind</link>
        <description>&lt;h3&gt;Function Binding&lt;/h3&gt;
&lt;p&gt;
	A &lt;dfn&gt;bind&lt;/dfn&gt; function wraps a function in a closure, 
	storing a reference 
	to the &lt;dfn&gt;context&lt;/dfn&gt; argument in the containing scope.
&lt;/p&gt;
&lt;p&gt;
    This allows the &lt;dfn&gt;bound&lt;/dfn&gt; function to run
    with a predetermined &lt;dfn&gt;context&lt;/dfn&gt;.
&lt;/p&gt;

&lt;h3&gt;Variable &lt;code&gt;this&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;
  When a function is passed as a reference, it loses its 
  base object. When the &lt;dfn&gt;unbound&lt;/dfn&gt; function is called, 
  the &lt;code&gt;this&lt;/code&gt; value is the global object.
&lt;/p&gt;

&lt;h3&gt;How Binding Works&lt;/h3&gt;
&lt;p&gt;
  By storing a reference to the desired object in a closure, 
  &lt;code&gt;this&lt;/code&gt; argument can be &lt;dfn&gt;bound&lt;/dfn&gt;. 
&lt;/p&gt;

&lt;p&gt;
	In it&#39;s simplest form, &lt;code&gt;bind&lt;/code&gt; looks like:-
&lt;/p&gt;

&lt;pre&gt;
Function.prototype.bind = &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;(&lt;var&gt;context&lt;/var&gt;) {
  &lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;fun&lt;/var&gt; = this;
  &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;(){
    &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;fun&lt;/var&gt;.apply(&lt;var&gt;context&lt;/var&gt;, arguments);
  };
};
&lt;/pre&gt;

&lt;h3&gt;Why Binding is Useful&lt;/h3&gt;
&lt;p&gt;
	Binding is often necessary when passing function references.
    For example:-
&lt;/p&gt;


&lt;pre&gt;
&lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;updater&lt;/var&gt; = {
  fetch : &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
    alert(this.time++);
  },
  time : 0
};
&lt;span class=&#39;comment&#39;&gt;// setTimeout(&lt;var&gt;updater&lt;/var&gt;.fetch, 500);&lt;/span&gt;
setTimeout(&lt;var&gt;updater&lt;/var&gt;.fetch.bind(&lt;var&gt;updater&lt;/var&gt;), 500);
&lt;/pre&gt;

&lt;p&gt;
  The commented-out call to &lt;code&gt;setTimeout&lt;/code&gt; would result in a 
  call to 
  &lt;code&gt;updater.fetch&lt;/code&gt; with the &lt;code&gt;global&lt;/code&gt; object 
  for the &lt;code&gt;this&lt;/code&gt; argument. &lt;code&gt;this.time&lt;/code&gt; would 
  be undefined, and &lt;code&gt;this.time++&lt;/code&gt; would result in 
  &lt;code&gt;NaN&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
  A &lt;dfn&gt;bind&lt;/dfn&gt; function that does &lt;em&gt;only&lt;/em&gt; binding
  accomplishes a trivial task.
  In most cases, a closure can just be used where binding is needed. 
&lt;/p&gt;

&lt;h3&gt;Binding in the Wild&lt;/h3&gt;
&lt;p&gt;
  Most JavaScript libraries handle binding internally. 
  These libraries also include a &lt;dfn&gt;partial apply&lt;/dfn&gt; for 
  their &lt;dfn&gt;bind&lt;/dfn&gt; function. 
&lt;/p&gt;

&lt;h3&gt;Partial Apply&lt;/h3&gt;
&lt;p&gt;
  &lt;dfn&gt;Partial application&lt;/dfn&gt; is setting parameter values of 
  a function call before it is called. 
  A &lt;dfn&gt;partial apply&lt;/dfn&gt; function usually looks like:-
&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;comment&quot;&gt;/** 
 * Return a function that prepends the 
 * arguments to partial to this call and 
 * appends any additional arguments.
 */&lt;/span&gt;
Function.prototype.partial = &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
  &lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;fun&lt;/var&gt; = &lt;span class=&#39;keyword&#39;&gt;this&lt;/span&gt;,
      &lt;var&gt;preArgs&lt;/var&gt; = Array.prototype.slice.call(arguments);
  &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
    &lt;var&gt;fun&lt;/var&gt;.apply(&lt;span class=&#39;keyword&#39;&gt;null&lt;/span&gt;, &lt;var&gt;preArgs&lt;/var&gt;.concat.apply(&lt;var&gt;preArgs&lt;/var&gt;, arguments));
  };
};
&lt;/pre&gt;
&lt;p&gt;
  This allows us to program in a dynamic, functional, 
  less OO way. For example:
&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt; setStyle(&lt;var&gt;style&lt;/var&gt;, &lt;var&gt;prop&lt;/var&gt;, &lt;var&gt;value&lt;/var&gt;) {
  &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;style&lt;/var&gt;[&lt;var&gt;prop&lt;/var&gt;] = &lt;var&gt;value&lt;/var&gt;;
}

&lt;span class=&quot;comment&quot;&gt;// Create a setBgColor function from 
// partial application of setStyle.&lt;/span&gt;
&lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;setBgColor&lt;/var&gt; = setStyle.partial(document.body.style, &quot;background&quot;);

&lt;span class=&quot;comment&quot;&gt;// Change the body&#39;s background color.&lt;/span&gt;
&lt;var&gt;setBgColor&lt;/var&gt;(&lt;span class=&#39;q&#39;&gt;&quot;red&quot;&lt;/span&gt;);
&lt;var&gt;setBgColor&lt;/var&gt;(&lt;span class=&#39;q&#39;&gt;&quot;#0f0&quot;&lt;/span&gt;);
&lt;/pre&gt;

&lt;h4&gt;Disadvantage&lt;/h4&gt;
&lt;p&gt;
  &lt;dfn&gt;Partial application&lt;/dfn&gt; requires an extra function call, 
  plus a call to &lt;em&gt;&lt;code&gt;concat&lt;/code&gt;&lt;/em&gt;
  for the extra arguments.
&lt;/p&gt;
&lt;p&gt;
  Partial application can make debugging trickier, since there is an 
  extra layer of indirection to the real method. 
&lt;/p&gt;
&lt;p&gt;
  &lt;dfn&gt;Bind&lt;/dfn&gt; + &lt;dfn&gt;partial apply&lt;/dfn&gt; can be used to force the 
  &lt;code&gt;this&lt;/code&gt; argument of a prototype method to 
  always be the of the instance. 
  This is inefficient and often leads to messy, 
  tangled function decomposition. Libraries that bind every method 
  do so out of ignorance of the language, and are best avoided.
&lt;/p&gt;

&lt;h3&gt;EcmaScript New Language Feature&lt;/h3&gt;
&lt;p&gt;
  The forthcoming version of EcmaScript (now called EcmaScript Harmony) 
  will include 
  &lt;code&gt;Function.prototype.bind(&lt;var&gt;context&lt;/var&gt;)&lt;/code&gt;. A native
  &lt;dfn&gt;bind&lt;/dfn&gt; should outperform any other &lt;dfn&gt;bind&lt;/dfn&gt; function.
&lt;/p&gt;
&lt;p&gt;
  This was something &lt;a href=&quot;http://peter.michaux.ca/&quot;&gt;Peter&lt;/a&gt; brought 
  up for EcmaScript 4, but appears to be making way into the revised 
  EcmaScript Harmony.
&lt;/p&gt;
&lt;p&gt;
  &lt;a href=&quot;http://www.erights.org/&quot;&gt;Mark Miller&lt;/a&gt; wrote out a &quot;self-hosted&quot; version of 
  EcmaScript&#39;s proposed &lt;code&gt;Function.prototype.bind&lt;/code&gt;.
  It is:-
&lt;/p&gt;

&lt;pre&gt;
Function.prototype.bind = &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;(&lt;var&gt;self&lt;/var&gt;, &lt;var&gt;var_args&lt;/var&gt;) {
   &lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;thisFunc&lt;/var&gt; = &lt;span class=&#39;keyword&#39;&gt;this&lt;/span&gt;;
   &lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;leftArgs&lt;/var&gt; = Array.slice(arguments, 1);
  &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;(&lt;var&gt;var_args&lt;/var&gt;) {
    &lt;span class=&#39;keyword&#39;&gt;var &lt;/span&gt;args = &lt;var&gt;leftArgs&lt;/var&gt;.concat(Array.slice(arguments, 0));
    &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;thisFunc&lt;/var&gt;.apply(&lt;var&gt;self&lt;/var&gt;, &lt;var&gt;args&lt;/var&gt;);
  };
};  
&lt;/pre&gt;
&lt;p&gt;
  After looking at the ES Harmony proposal, and looking at a 
  few versions of bind functions, I decided to write a better one 
  that does exactly what the ES Harmony&#39;s bind does, but with 
  greater efficiency than the current libraries offer, and whose,
  &lt;code&gt;length&lt;/code&gt; property was &lt;code&gt;1&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
  Although unnecessary, this is a welcome addition to the language.
  A native bind will outperform any user-defined bind function 
  and will result in fewer closures.
&lt;/p&gt;

&lt;h3&gt;The Rundown&lt;/h3&gt;
&lt;p&gt;
  Before I give a critique and rundown, I have a test.
&lt;/p&gt;
&lt;h4&gt;&lt;a href=&quot;/test/blog/bind/BindFunction.html&quot;&gt;Library Comparison Test&lt;/a&gt;&lt;/h4&gt;


&lt;ol&gt;
	&lt;li&gt;Garrett&#39;s Bind
		&lt;p&gt;
		 This bind was, by far, the most efficient in 
		 tests #1, and #4, and nearly ties Base 2 in test #2 
		 (Base 2 was about .5 ms faster) . 
		 This function requires no additional code or functions. 
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/base2/&quot;&gt;Base2&lt;/a&gt; 
	&lt;code&gt;bind&lt;/code&gt;
		&lt;p&gt;
		  Second performance-wise. 
		&lt;/p&gt;
		&lt;p&gt;
		  Requires only a 
		  top level &lt;code&gt;_slice&lt;/code&gt; function (trivial), and performs 
		  a strategy for extra arguments.  
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://dojotoolkit.org/&quot;&gt;Dojo&lt;/a&gt;&#39;s hitch
		&lt;p&gt;
		  Dojo was fast with pure bind, but slower with partial apply. 
		&lt;/p&gt;
		&lt;p&gt;
		  This function requires many other functions and has an additional 
		  complication of accepting strings and arguments of different order.
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt; &lt;a href=&quot;http://extjs.com/&quot;&gt;Ext-js&lt;/a&gt; 
	  &lt;code&gt;Function.prototype.createDelegate&lt;/code&gt; 
		&lt;p&gt;
		  Performance was slow.  
		  This function requires no importing of external functions.
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;Mark Miller&#39;s &lt;code&gt;bind&lt;/code&gt;
		&lt;p&gt;
		  Requires no external dependencies. While it gets a 10 for simplicity
		  and aesthetics, this function was not as fast, and for pure bind 
		  (no &lt;dfn&gt;partial apply&lt;/dfn&gt;) was not nearly as fast as it 
		  should be.
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;
		  &lt;a href=&quot;http://prototypejs.org/&quot;&gt;Prototype&lt;/a&gt;&#39;s 
		  &lt;code&gt;Function.prototype.bind&lt;/code&gt;
		&lt;p&gt;
		  Performance was fair.
		  Requires several extra functions + browser detection. The function 
		  is used very heavily internally.
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://mootools.net/&quot;&gt;Mootools&lt;/a&gt; 
	    &lt;code&gt;Function.prototype.bind&lt;/code&gt;
		&lt;p&gt;
		  Performance times were poor and
		  the results for two tests were wrong. &lt;del&gt;were wrong&lt;/del&gt;. 
		&lt;/p&gt;
		&lt;p&gt;&lt;ins&gt;
		  The entire mootools.js is required for the bind function. 
		  The library adds a &lt;code&gt;$family&lt;/code&gt; property, and makes 
		  other changes to &lt;code&gt;Array.prototype&lt;/code&gt;. 
		  &lt;/ins&gt;
		&lt;/p&gt;
	&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://developer.yahoo.com/yui/3/&quot;&gt;YUI 3 &lt;/a&gt; 
	  &lt;code&gt;bind&lt;/code&gt;
	  &lt;p&gt;
	    Performance time was fair.
	    The results for test#2 are wrong because the 
	    call&#39;s arguments are prepended, not appended. This is by design.
	  &lt;/p&gt;
	  &lt;p&gt;
	    Having the call&#39;s arguments &lt;em&gt;prepended&lt;/em&gt; 
	    is an unusual design decision. It might seem
	    unintuitive, and confuse developers who are used 
	    to the more common version, as seen in Prototype, Base2, 
	    and the official EcmaScript proposal.
	  &lt;/p&gt;
	  &lt;p&gt;
	    The amount of code YUI&#39;s bind depends on is staggering. 
	  &lt;/p&gt;
	&lt;/li&gt;
	
&lt;/ol&gt;

&lt;h3&gt;Pass the Parme&amp;#378;an&lt;/h3&gt;
&lt;p&gt;
  Many of the libraries have long chains of function calls. 
  A bind function does not need and should not require the 
  inclusion of several other functions.
&lt;/p&gt;

&lt;p&gt;
  Prototype JS requires the &lt;code&gt;$A&lt;/code&gt; function, which requires 
  &lt;code&gt;Prototype.Browser&lt;/code&gt; to determine 
  which &lt;code&gt;$A&lt;/code&gt; function. Browser detection has absolutely 
  no place in Function binding. (&lt;code&gt;$A&lt;/code&gt; also calls 
  &lt;code&gt;toArray&lt;/code&gt; conditionally, but that will not happen in this case.)
&lt;/p&gt;

&lt;p&gt;
  Dojo is almost as bad. 
  Dojo&#39;s &lt;code&gt;hitch&lt;/code&gt; function has the arguments in reverse order and 
  requires &lt;code&gt;dojo.global&lt;/code&gt;, 
  &lt;code&gt;dojo._hitchArgs&lt;/code&gt;, &lt;code&gt;dojo._toArray&lt;/code&gt;, 
  and &lt;code&gt;dojo.isString&lt;/code&gt;. 
&lt;/p&gt;

&lt;p&gt;
  Mootools has very strewn code. The broken bind 
  function required an additional 108 lines of Mootools. 
&lt;/p&gt;
&lt;p&gt;
  YUI is the most grandiose.
  Function &lt;code&gt;YUI.bind(f, o)&lt;/code&gt; is found in 
  &quot;&lt;samp&gt;oop.js&lt;/samp&gt;&quot;. File &lt;samp&gt;oop.js&lt;/samp&gt;
  requires over 120k of &quot;prerequisite&quot; files in 
  &lt;samp&gt;yui.js&lt;/samp&gt; and &lt;samp&gt;yui-base.js&lt;/samp&gt;, 
  coming to a total of over 160k. Just for bind. YUI 3 seems to suffer 
  from over-engineering and &lt;abbr title=&quot;Big Up Front Design&quot;
  &gt;BUFD&lt;/abbr&gt;, which is typical in waterfall shops.
  &lt;/p&gt;
&lt;p&gt;
  YUI&#39;s &#39;array&#39; module did not seem to load or evaluate properly, so 
  code from the yui-base file was copy-pasted.
&lt;/p&gt;

&lt;h3&gt;Worth Using?&lt;/h3&gt;
&lt;p&gt;
  The best bind functions are fast, do not require 
  other library functions, and are fairly simple. 
&lt;/p&gt;
&lt;h4&gt;But is a Bind Function Necessary?&lt;/h4&gt;
&lt;p&gt;
  No. Binding can be achieved with an inline closure 
  where it is needed
  and partial application is not necessary.  
&lt;/p&gt;

&lt;p&gt;
  Here is example 1, without using bind.
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;updater&lt;/var&gt; = {
  fetch : &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
    alert(&lt;span class=&#39;keyword&#39;&gt;this&lt;/span&gt;.time++);
  },
  time : 0
};
setTimeout(&lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() { &lt;var&gt;updater&lt;/var&gt;.fetch(); }, 500);
&lt;/pre&gt;
&lt;p&gt;
  A native &lt;code&gt;Function.prototype.bind&lt;/code&gt; will allow 
  for cleaner binding, without the need for creating 
  a closure. As native code, it will be faster and more reliable.
  &lt;code&gt;Function.prototype.bind&lt;/code&gt; is not necessary, 
  but is a welcome addition to the language.
&lt;/p&gt;

&lt;h4&gt;Why All the Fuss?&lt;/h4&gt;
&lt;p&gt;
  Being aware of what libraries do and identifying and learning 
  from the mistakes of libraries helps developers avoid such 
  mistakes by learning what the library does. Developers
  do not need the burden of large, tangled, and often 
  buggy library dependencies.
&lt;/p&gt;

&lt;h4&gt;Look at The Code&lt;/h4&gt;
&lt;p&gt;
  &lt;em&gt;What&lt;/em&gt; the library&#39;s bind function does and &lt;em&gt;how&lt;/em&gt; the library uses 
  that function internally is a step to take in assessing 
  the library&#39;s quality.  
&lt;/p&gt;

&lt;p&gt;
  A developer can make a more responsible and 
  professional choice by avoiding a library that makes 
  heavy use of a slow-spaghetti bind function.
&lt;/p&gt;

&lt;h3&gt;My Version&lt;/h3&gt;

&lt;p&gt;
  The following function is
  the fastest bind function for pure bind (no partial apply). 
  It is more than three times as fast as Base2, the second fastest bind 
  function tested here. 
&lt;/p&gt;
&lt;p&gt;
  Here is my version of the bind function.
&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;comment&quot;&gt;/**
 * @param {Object} context the &#39;this&#39; value to be used.
 * @param {arguments} [1..n] optional arguments that are
 * prepended to returned function&#39;s call.
 * @return {Function} a function that applies the original
 * function with &#39;context&#39; as the thisArg.
 */&lt;/span&gt;
Function.prototype.bind = &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;(&lt;var&gt;context&lt;/var&gt;){
  &lt;span class=&#39;keyword&#39;&gt;var&lt;/span&gt; &lt;var&gt;fn&lt;/var&gt; = &lt;span class=&#39;keyword&#39;&gt;this&lt;/span&gt;, 
      &lt;var&gt;ap&lt;/var&gt;, &lt;var&gt;concat&lt;/var&gt;, &lt;var&gt;args&lt;/var&gt;,
      &lt;var&gt;isPartial&lt;/var&gt; = arguments.length &gt; 1;
  &lt;span class=&quot;comment&quot;&gt;// Strategy 1: just bind, not a partialApply&lt;/span&gt;
  &lt;span class=&#39;keyword&#39;&gt;if&lt;/span&gt;(!&lt;var&gt;isPartial&lt;/var&gt;) {
    &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
        &lt;span class=&#39;keyword&#39;&gt;if&lt;/span&gt;(arguments.length !== 0) {
          &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;fn&lt;/var&gt;.apply(context, arguments);
        } &lt;span class=&#39;keyword&#39;&gt;else&lt;/span&gt; {
          &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;fn&lt;/var&gt;.call(&lt;var&gt;context&lt;/var&gt;); &lt;span class=&#39;comment&#39;&gt;// faster in Firefox.&lt;/span&gt;
        }
      };
    } &lt;span class=&#39;keyword&#39;&gt;else&lt;/span&gt; {
    &lt;span class=&quot;comment&quot;&gt;// Strategy 2: partialApply&lt;/span&gt;
    &lt;var&gt;ap&lt;/var&gt; = Array.prototype,
    &lt;var&gt;args&lt;/var&gt; = &lt;var&gt;ap&lt;/var&gt;.&lt;var&gt;slice&lt;/var&gt;.call(arguments, 1);
    &lt;var&gt;concat&lt;/var&gt; = &lt;var&gt;ap&lt;/var&gt;.concat;
    &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;span class=&#39;keyword&#39;&gt;function&lt;/span&gt;() {
      &lt;span class=&#39;keyword&#39;&gt;return&lt;/span&gt; &lt;var&gt;fn&lt;/var&gt;.apply(context, 
        arguments.length === 0 ? &lt;var&gt;args&lt;/var&gt; : 
        &lt;var&gt;concat&lt;/var&gt;.apply(&lt;var&gt;args&lt;/var&gt;, arguments));
    };
  }
};
&lt;/pre&gt;
&lt;p&gt;
  This function was not included in 
  &lt;a href=&quot;http://dhtmlkithcen.com/ape/&quot;&gt;APE&lt;/a&gt; 
  because it was not needed. This function may be used by libraries who wish to 
  continue using a bind function with the benefit of faster performance. 
&lt;/p&gt;
</description>
	    <dc:date>2008-09-11T17:20:00-05:00</dc:date>
	                                <wfw:comment>http://dhtmlkitchen.com/commentapi/default/JavaScript/2008/09/11/Function-prototype-bind</wfw:comment>
            <wfw:commentRss>http://dhtmlkitchen.com/news/default/2008/09/11/Function-prototype-bind?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://dhtmlkitchen.com/news/default/2008/07/04/Find-Element-Position">
	    <title>Find Element Position</title>
	    <link>http://dhtmlkitchen.com/news/default/2008/07/04/Find-Element-Position</link>
        <description>&lt;p&gt;Most libraries try provide some functionality for finding an element&#39;s position, but fail in all but the simplest cases.
&lt;/p&gt;

&lt;p&gt;
I created a test page to demonstrate the libraries&#39; results of finding an element&#39;s position 
and the time it takes for them to succeed or fail. 
&lt;/p&gt;

&lt;h3&gt;Test Page&lt;/h3&gt;
&lt;p&gt;
&lt;a href=&quot;/ape/example/dom/compare/&quot;&gt;Compare JavaScript Libraries&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;Demos are Not Unit Tests&lt;/h3&gt;
&lt;p&gt;
These two demos don&#39;t cover all of the complexities in finding an element&#39;s position. I didn&#39;t even touch tables.
There are also complications with padding and border on HTML root element. Unfortunately, IE8b1 doesn&#39;t support CSS
on the HTML root element (&lt;a href=&quot;https://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=354453&quot;&gt;connect id 354453&lt;/a&gt;), so it can&#39;t be tested.
&lt;/p&gt;

&lt;p&gt;APE guards against all of the other problems by having a &lt;a href=&quot;/ape/test/tests/dom/position-f-test.html&quot;&gt;test suite&lt;/a&gt; that 
tests this function with combinations of these cases. 
&lt;/p&gt;
</description>
	    <dc:date>2008-07-04T02:36:21-05:00</dc:date>
	        </item>
            <item rdf:about="http://dhtmlkitchen.com/news/default/2008/06/17/Prototype-js-A-Review">
	    <title>Prototype.js - A Review</title>
	    <link>http://dhtmlkitchen.com/news/default/2008/06/17/Prototype-js-A-Review</link>
        <description>&lt;p&gt;
    I was prompted to do a code review on PrototypeJS. Here is a partial review. 
&lt;/p&gt;

&lt;h3&gt;Ten Issues&lt;/h3&gt;

&lt;ul&gt;
    &lt;li&gt;Modification of Host Object - Non standard, doesn&#39;t work the same in all browsers. Don&#39;t do it!
    &lt;/li&gt;
    &lt;li&gt;Class.Methods.addMethods - 
        &lt;ul&gt;
            &lt;li&gt;Don&#39;t rely on a Function&#39;s &lt;code&gt;toString&lt;/code&gt;!&lt;/li&gt;
            &lt;li&gt;Don&#39;t introduce special behavior based on function Decompilation!&lt;/li&gt;
            &lt;li&gt;The mimicing of class based inheritance through closures to get &lt;code&gt;$super&lt;/code&gt; 
                to work requires a significantly augmented scope chain. 
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li&gt;The Dollar Function - Meaningless and extremely inefficient
    &lt;/li&gt;
    &lt;li&gt;
        Element.Methods.visible - misnamed, non-reflective, and buggy/unreliable! 
    &lt;/li&gt;
    &lt;li&gt;
        More Modifications to Host objects
    &lt;/li&gt;
    &lt;li&gt; 
        Object.extend - Don&#39;t forget the JScript DontEnum bug!
    &lt;/li&gt;
    &lt;li&gt;
        $A - Relying on object&#39;s toString - 
    &lt;/li&gt;
    &lt;li&gt;
        readAttribute - Don&#39;t rely on Function Decompilation
    &lt;/li&gt;
    &lt;li&gt;
        Ajax.Request - Add an Underscore?
    &lt;/li&gt;
    &lt;li&gt;
        Broken unescaping of HTML Strings 
    &lt;/li&gt;
    &lt;li&gt;
        Unnecessary use of &lt;code&gt;with&lt;/code&gt; statement
    &lt;/li&gt;
    &lt;li&gt;
        Enumerable.include - Strict Equality or 2n with Loose Equality
    &lt;/li&gt;
    &lt;li&gt;
        getDimensions - Don&#39;t Expect clientWidth to be non-zero in IE
    &lt;/li&gt;
    &lt;li&gt;
        cumulativeOffset - doesn&#39;t account for borders, scroll offsets, or magic BODY.
    &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
    Okay, so it&#39;s more than 10, and could be even more, but I have to stop somewhere!
&lt;/p&gt;

&lt;h3&gt;Modification of Host Object&lt;/h3&gt;
    &lt;p&gt;
        A Host object is an object provided by the Host environment, e.g. &lt;code&gt;document&lt;/code&gt;, &lt;code&gt;event&lt;/code&gt;, an element.
    &lt;/p&gt;

    &lt;p&gt;
        PrototypeJS relies on modifying Host objects as a part of its core approach. There are several 
        problems with this approach.
    &lt;/p&gt;
    &lt;ul&gt;
        &lt;li&gt;
        There is 
        no requirement in the EcmaScript specification that requires Host objects to be 
        modifiable (although they usually are).
        &lt;/li&gt;
        &lt;li&gt;
        There is no requirement in the EcmaScript specification that the Host 
        environment expose for its Host objects
        a constructor with an associated prototype.
        &lt;/li&gt;
        &lt;li&gt;
        There is no requirement in the EcmaScript specification that objects expose 
        a &lt;code&gt;__proto__&lt;/code&gt; property.
        &lt;/li&gt;
        &lt;li&gt;
        There is no guarantee by any standard that there will be a 
        &lt;code&gt;__proto__&lt;/code&gt; property present for an &lt;code&gt;Element&lt;/code&gt; or what value, if any, it will hold. 
        &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
    The fact that Mozilla exposes the prototypes of Element, et c is useful in that it allows 
    developers to provide quick patches for new or broken features that lack proper support. 
    However, this feature can&#39;t be reliably used for websites that are expected to run in multiple browsers.
&lt;/p&gt;

&lt;h3&gt;Class.Methods.addMethods&lt;/h3&gt;
&lt;p&gt;
Class.Methods.addMethods relies on the approach of calling &lt;code&gt;toString&lt;/code&gt; on a function, 
expecting to get back the source code, as it originally appeared. 
&lt;/p&gt;

&lt;pre&gt;
if(value.argumentNames().first() == &quot;$super&quot;)
&lt;/pre&gt;

&lt;p&gt;
A few significant problems:
&lt;/p&gt;

&lt;ul&gt;
     &lt;li&gt;
        &lt;p&gt;
        &lt;em&gt;&lt;code&gt;Function.prototype.toString&lt;/code&gt; is not required to return the source code of the function&lt;/em&gt;
        &lt;/p&gt;
        &lt;p&gt;
        Function.prototype.toString is guaranteed only to return an implementation-dependent 
        representation of the function as a FunctionDeclaration [or FunctionExpression] (spec errata, has been fixed).
        (&lt;a href=&quot;http://bclary.com/2004/11/07/#a-15.3.4.2&quot;&gt;&amp;#167;15.3.4.2&lt;/a&gt;).
        &lt;/p&gt;

        &lt;p&gt;
        Opera mobile 
        &lt;a href=&quot;http://my.opera.com/hallvors/blog/show.dml/1665828#comment4460978&quot;&gt;follows the spec&lt;/a&gt; 
        but takes the liberty of not returning the source code of the function. 
        &lt;/p&gt;
    &lt;/li&gt;

    &lt;li&gt;
        Even if relying on the name of a function&#39;s formal parameter were guaranteed, 
        doing so would make implementation code fragile because it would be impossible for a human 
        (or compressor) to rename it (&lt;a href=&quot;http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=1957852&amp;amp;group_id=165715&amp;amp;atid=836476&quot;
        title=&#39;[#1918232] Prevent munging arguments whose name start w/ &quot;$&quot;&#39;
        &gt;YUI Compressor bug&lt;/a&gt;).

&lt;pre&gt;Object.extend(Function.prototype, {
  argumentNames: function() {
    var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(&quot;,&quot;).invoke(&quot;strip&quot;);
    return names.length == 1 &amp;amp;&amp;amp; !names[0] ? [] : names;
  },
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

    &lt;p&gt;
        Providing a &lt;code&gt;toString&lt;/code&gt; that returns helpful debugging info 
        for objects is generally good advice. 
    &lt;/p&gt;
    &lt;p&gt;
        However, the return value of a function&#39;s &lt;code&gt;toString&lt;/code&gt; cannot be expected to be anything 
        other than a string value. It should not be relied on.
        Unfortunately 
        &lt;code&gt;argumentNames&lt;/code&gt; will choke on a 
        Function object that has a custom &lt;code&gt;toString&lt;/code&gt;. This problem will happen in every browser.
    &lt;/p&gt;
    &lt;h4&gt;Example: Programmer-defined toString Causes Problem with Object.extend&lt;/h4&gt;
&lt;pre&gt;
function WidgetFactory(){}
WidgetFactory.toString = function(){ return&quot;[WidgetFactory constructor]&quot;; };
&lt;/pre&gt;
    &lt;p&gt;
    If &lt;code&gt;argumentNames()&lt;/code&gt; is called on WidgetFactory, the first call to match() will return null. Then, when 
    split() is called, a TypeError will be thrown.
    &lt;/p&gt;

    &lt;p&gt;
    It would be less error-prone for PrototypeJS to use:
    &lt;/p&gt;
    &lt;pre&gt;
    var names = Function.prototype.toString.call(someFunction);
    &lt;/pre&gt;
    &lt;p&gt;
    This avoids the mistake of relying on the function instance&#39;s &lt;code&gt;toString&lt;/code&gt;, 
    however, the approach still has two significant problems:
    &lt;/p&gt;
    &lt;ol&gt;
        &lt;li&gt;relies on the source code and named formal 
    parameters of the function on which it is called (problem 1). 
        &lt;/li&gt;
        &lt;li&gt;
            &lt;em&gt;&lt;code&gt;Function.prototype.toString&lt;/code&gt; is &lt;em&gt;still&lt;/em&gt; not required to return the source code of the function&lt;/em&gt;
            Function.prototype.toString is guaranteed to return an implementation-dependent 
            representation of the function as a FunctionDeclaration [or FunctionExpression] (spec errata).
            (&lt;a href=&quot;http://bclary.com/2004/11/07/#a-15.3.4.2&quot;&gt;&amp;#167;15.3.4.2&lt;/a&gt;), 
            and in fact, Opera mobile 
            &lt;a href=&quot;http://my.opera.com/hallvors/blog/show.dml/1665828#comment4460978&quot;&gt;follows the spec correctly&lt;/a&gt;,
            but takes the liberty of not returning the source code of the function. 
        &lt;/li&gt;
    &lt;/ol&gt;

&lt;h3&gt;Relying on Function Objects&#39; toString&lt;/h3&gt;

&lt;p&gt;Do Not Rely on Return Values from Function Objects&#39; toString!&lt;/p&gt;

&lt;p&gt;
    In general, &lt;code&gt;toString&lt;/code&gt; should not be parsed or relied upon for data formats. 
    &lt;code&gt;toString&lt;/code&gt; is useful for debugging. In October 2007, I 
    pointed out how &lt;a href=&quot;http://dhtmlkitchen.com/?category=/JavaScript/&amp;amp;date=2007/10/10/&amp;amp;entry=How-to-Tell-if-an-Object-is-a-Function&quot;&gt;Dojo and jQuery&lt;/a&gt; made this mistake. Hallvord has been writing against relying on Function Decompilation for 
    well over a year, as it resulted in &lt;a href=&quot;http://my.opera.com/hallvors/blog/index.dml/tag/decompile&quot;
    &gt;problems in PrototypeJS and jQuery&lt;/a&gt; running in Opera Mobile. 
&lt;/p&gt;

&lt;h3&gt;The Dollar Function&lt;/h3&gt;

&lt;p&gt;
PrototypeJS is built on the approach of modifying Host objects. This is the cornerstone of the library&#39;s problems.
The library will try to modify the built-in prototype of an XPConnect wrapped prototype if it assumes 
the browser can do that. Otherwise, it will add properties to the element itself. 
&lt;/p&gt;

&lt;p&gt;
    The primary accessor to these modified Host objects is through that dollar function.
&lt;/p&gt;

&lt;h4&gt;Law of Demeter&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;
Each unit should have only limited knowledge about other units: only units &quot;closely&quot; related to the current unit.
(&lt;a href=&quot;http://en.wikipedia.org/wiki/Law_of_Demeter&quot;&gt;LoD&lt;/a&gt;). 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
    I&#39;ll come back to explain how Prototype.js&#39; modifications to Host objects violate LoD, and the problems 
    associated with that.
&lt;/p&gt;

&lt;h4&gt;What Does $ Do?&lt;/h4&gt;

&lt;ul&gt;
    &lt;li&gt;
    $ does not have a clearly defined meaning as to what the function actually does.
    &lt;/li&gt;
    &lt;li&gt;
     The dollar sign is intended to be reserved for machine-generated code.  
    &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
PrototypeJS &lt;code&gt;$&lt;/code&gt; function gets an element or array of elements. Calling &lt;code&gt;$&lt;/code&gt; results in a bare minimum of three function calls: &lt;code&gt;$&lt;/code&gt;, &lt;code&gt;isString&lt;/code&gt;, and &lt;code&gt;Element.extend&lt;/code&gt; and a maximum of over 135 function calls.
&lt;/p&gt;
&lt;pre&gt;
function $(element) { 
  if (arguments.length &amp;gt; 1) { 
    for (var i = 0, elements = [], length = arguments.length; i &amp;lt; length; i++) 
      elements.push($(arguments[i])); 
    return elements; 
  } 
  if (Object.isString(element)) 
    element = document.getElementById(element); 
  return Element.extend(element); 
} 
&lt;/pre&gt;
&lt;h4&gt;Call Stack of $ (best case)&lt;/h4&gt;
&lt;pre&gt;
$ -&gt; isString
  -&gt; document.getElementById
  -&gt; Element.extend
&lt;/pre&gt;

&lt;h4&gt;Count of Functions from $ (best case)&lt;/h4&gt;
&lt;pre&gt;
$................................+1 
 +--isString.....................+1
 +--document.getElementById.....(+1) (when isString(element) is true) 
 +--Element.extend...............+1 
    ~--Prototype.K||(anonymous)...0 (alias, second time, only. Prototype.K only if SpecificElementExtensions)
Sub-total_________________________3 (4 when isString(element) is true).
&lt;/pre&gt;

&lt;p&gt;Calling  $(document) then $(document), there will be many function calls the first time, and never any fewer than three
calls the second time.
&lt;/p&gt;

&lt;pre&gt;
Element.extend = (function() {
  if (Prototype.BrowserFeatures.SpecificElementExtensions)
    return Prototype.K;

  var Methods = { }, ByTag = Element.Methods.ByTag;
  Object.extend(function(element) { 
      if (!element || element._extendedByPrototype || 
          element.nodeType != 1 || element == window) return element; 
      var methods = Object.clone(Methods), 
        tagName = element.tagName, property, value; 
      // extend methods for specific tags 
      if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]); 
      for (property in methods) { 
        value = methods[property]; 
        if (Object.isFunction(value) &amp;amp;&amp;amp; !(property in element)) 
          element[property] = value.methodize(); 
      } 
       element._extendedByPrototype = Prototype.emptyFunction; 
      return element; 
  }, {
    refresh: function() {
      // extend methods for all tags (Safari doesn&#39;t need this)
      if (!Prototype.BrowserFeatures.ElementExtensions) {
        Object.extend(Methods, Element.Methods);
        Object.extend(Methods, Element.Methods.Simulated);
      }
    }

  extend.refresh();
  return extend;
})();
&lt;/pre&gt; 

&lt;h3&gt;Element.extend, first call&lt;/h3&gt;
&lt;p&gt;
However, during the first call to $(document), there is a check to Prototype.BrowserFeatures.SpecificElementExtensions. 
This is done because when SpecificElementExtensions is true, then the Library attempts to add the properties to  
DOM interface prototypes, e.g. HTMLHeadingElement.prototype. This happens elsewhere in the code, only when 
a __proto__ property returns a truthy value on created elements. If this feature is supported, the author has 
makes modifications to the DOM object interfaces, e.g. &quot;HTML&quot; + element.tagName + &quot;Element&quot;, et c, but only
when the userAgent does not match /Apple.*Mobile.*Safari/. (He makes said modifications elsewhere in the code, 
Element.addMethods -&gt; findDOMClass).
&lt;/p&gt;

&lt;p&gt;
Element.extend&#39;s closure calls Object.extend (needs review) to add the refresh() 
method to element.extend (rather than perform a simple assignment).
The closure then calls extend.refresh() before returning the method extend, 
which gets assigned to Element.extend.
&lt;/p&gt;

&lt;pre&gt;
+ Element.extend&#39;s closure -&gt; Object.extend -&gt; extend.refresh -&gt; Object.extend...3
                                      Object.extend...1
subtotal:_____________________________________________9
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;calls: 5&lt;/strong&gt;, &lt;strong&gt;Depth: 3&lt;/strong&gt;
These calls are done when the file is loaded. They don&#39;t affect performance of &lt;code&gt;$&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
After extend has been assigned to Element.extend, it is invoked. 
Element.extend calls Object.clone, which calls Object.extend, then ByTag, Object.extend, n calls to isFunction, 
 n calls to methodize, where &lt;var&gt;n&lt;/var&gt; is the number of properties of &lt;var&gt;methods&lt;/var&gt;.
The element is then &quot;methodized&quot;, which adds Ajax, et c to a FORM element. 
&lt;/p&gt;
&lt;pre&gt;
$ -&gt; isString..........................................(2)
     document.getElementById...........................(+1) (when isString(element) is true)
     Element.extend -&gt;  Object.clone -&gt; Object.extend..(2)
                        ByTag -&gt; Object.extend.........(2) (depends on tagName).
                        isFunction.....................(n = Size(methods) = 64 + 8)
                        methodize......................(n = Size(methods) = 64 + 8)
Total:_________________________________________________151
&lt;/pre&gt;

&lt;p&gt;
    Calling $(&quot;sp-searchtext&quot;) results in 151 function calls the first time it is called.
    Non-form elements will have 133 calls the first time.
&lt;/p&gt;

&lt;p&gt;
    This happens for every object that is got by dollar function for browsers that don&#39;t 
    support modifying DOM prototypes. 
&lt;/p&gt;

&lt;p&gt;
It considerably more complex and inefficient the first time around, when SpecificElementExtensions is false:&lt;/p&gt;
&lt;pre&gt;
Object.extend(Methods, Element.Methods);
Object.extend(Methods, Element.Methods.Simulated);
&lt;/pre&gt;

&lt;h4&gt;Where is $ Used Internally?&lt;/h4&gt;
&lt;p&gt;
    All of the &lt;code&gt;Element.methods&lt;/code&gt; of PrototypeJS functions (the ones that got &quot;methodized&quot; in dollar,
    use the dollar function, as well, adding extra overhead of a function call. 
&lt;/p&gt;

&lt;p&gt;
    This allows each of &lt;code&gt;Element.methods&lt;/code&gt; to be used as a static method. This also adds considerable extra 
    cost, though, to each call. 
&lt;/p&gt;

&lt;pre&gt;
Element.Methods = {
&lt;span class=&quot;error&quot;&gt;// (GS) visibility is not display!&lt;/span&gt;
  visible: function(element) {
&lt;span class=&quot;error&quot;&gt;// (GS) style properties do not reflect element state.&lt;/span&gt;
&lt;span class=&quot;error&quot;&gt;// The value &#39;inherit&#39; is not considered.&lt;/span&gt;
    return $(element).style.display != &#39;none&#39;;
  },
&lt;/pre&gt;
&lt;p&gt;
    &lt;code&gt;Element.Methods.visible&lt;/code&gt; does not deal with CSS &lt;code&gt;visibility&lt;/code&gt;, but instead 
    returns the &lt;code&gt;style.display != &#39;none&#39;&lt;/code&gt;. The 
    &lt;code&gt;display&lt;/code&gt; property does not reflect the &lt;code&gt;currentStyle&lt;/code&gt; or computed style.
    Also, the CSS
    &lt;a href=&quot;http://www.w3.org/TR/CSS21/visuren.html#display-prop&quot;&gt;display property&lt;/a&gt; 
    can have the value &lt;a href=&quot;http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit&quot;&gt;inherit&lt;/a&gt;.
&lt;/p&gt;
 
&lt;p&gt;
    Other &lt;code&gt;Element.Methods&lt;/code&gt; functions that use the dollar function are more expensive. For example:
&lt;/p&gt;
&lt;pre&gt;
&lt;span class=&quot;error&quot;&gt;// (GS) Avoid this long chains of calls. Hard to debug.&lt;/span&gt;
&lt;span class=&quot;error&quot;&gt;// (GS) calling Element.extend on each element is expensive, 
// up to 1600+ function calls for a FORM with 10 elements in IE.
&lt;/span&gt;
  descendants: function(element) {
    return $A($(element).getElementsByTagName(&#39;*&#39;)).each(Element.extend);
  },

&lt;em&gt;...&lt;/em&gt;

var Enumerable = {
  each: function(iterator, context) {
    var index = 0;
    iterator = iterator.bind(context);
    try {
      this._each(function(value) {
        iterator(value, index++);
      });
    } catch (e) {
      if (e != $break) throw e;
    }
    return this;
  },

&lt;em&gt;...&lt;/em&gt;


Object.extend(Array.prototype, {
  _each: function(iterator) {
    for (var i = 0, length = this.length; i &amp;lt; length; i++)
      iterator(this[i]);
  },
&lt;/pre&gt;


&lt;p&gt;
    Considering a &lt;code&gt;FORM&lt;/code&gt; with 10 &lt;code&gt;input&lt;/code&gt; elements and nothing else,
    there will be:
&lt;/p&gt;
&lt;pre&gt;
Element.descendants...................1
    $A--&gt;Array........................2
     +--$.............................151
        +--getElementsByTagName(&#39;*&#39;)..1
     each.............................1 x 10 (ten INPUT elements)
      +--bind.........................1 x 10 
      +--_each........................151 x 10 (151 methods, ten INPUT elements)
TOTAL.................................1685
&lt;/pre&gt;

&lt;p&gt;
    One thousand, six hundred, and eighty-five function calls. 
&lt;/p&gt;

&lt;p&gt;
The call to &lt;code&gt;isFunction&lt;/code&gt; in &lt;code&gt;Element.extend&lt;/code&gt; might be something that could be refactored:
&lt;/p&gt;
&lt;pre&gt;
value = methods[property];
Object.isFunction(value)
&lt;/pre&gt;

&lt;p&gt;Variable &lt;code&gt;&lt;var&gt;methods&lt;/var&gt;&lt;/code&gt; is a collection of functions. 
Calling &lt;code&gt;Object.isFunction(&lt;var&gt;value&lt;/var&gt;)&lt;/code&gt; should always return true here and this is something 
that the author can have control over because he owns &lt;code&gt;&lt;var&gt;methods&lt;/var&gt;&lt;/code&gt; (Law of Demeter).
&lt;/p&gt;

&lt;h4&gt;Always Use Dollar&lt;/h4&gt;
&lt;p&gt;
When using PrototypeJS, it is uncertain what properties will be present on an Element. This is because 
PrototypeJS may have already modified that element or its associated prototype. This dilemma of ambiguity can 
be avoided by the PrototypeJS user always using the dollar function and depending on PrototypeJS. 
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;$(&quot;adiv&quot;).parentNode.show()&lt;/code&gt;, will have unexpected results, and will result in error in IE, 
if the parentNode has not been previously modified via Element.extend()
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;$($(&#39;adiv&#39;).parentNode)&lt;/code&gt;, will result in no less than seven function calls, and that is only after 
&lt;code&gt;$(&#39;adiv&#39;)&lt;/code&gt; has been called and 
&lt;code&gt;$($(&#39;adiv&#39;).parentNode)&lt;/code&gt; has been called. 
&lt;/p&gt;

&lt;h3&gt;More Modifications to Host Objects&lt;/h3&gt;

&lt;p&gt;
I&#39;m going to back up a little bit and look at details I skipped over, the modification Host objects. 
&lt;/p&gt;

&lt;h4&gt;LoD Recap&lt;/h4&gt;
&lt;p&gt;
    If the implementation&#39;s 
    internal code undergoes change, or if other browsers provide similar properties with 
    slightly different implementation then the code that relies on 
    assumptions of implementation-specific details based on those properties (&lt;code&gt;col.__proto__&lt;/code&gt;) 
    will fail. Implementations have been known to change, in this regard 
    (&lt;a title=&quot;Bug 390411 – Can&#39;t override getElementsByClassName by setting it on HTMLElement.prototype&quot;
    href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=390411&quot;&gt;bug 390411&lt;/a&gt;) 
&lt;/p&gt;

&lt;pre&gt;
function findDOMClass(tagName) {
    var klass;
    var trans = {
      &quot;OPTGROUP&quot;: &quot;OptGroup&quot;, &quot;TEXTAREA&quot;: &quot;TextArea&quot;, &quot;P&quot;: &quot;Paragraph&quot;,
// (GS) et c...    
    };

    if (trans[tagName]) klass = &#39;HTML&#39; + trans[tagName] + &#39;Element&#39;;

&lt;span class=&quot;error&quot;&gt;// (GS) Does not provide any feature detection about the object.&lt;/span&gt;
    if (window[klass]) return window[klass];
    klass = &#39;HTML&#39; + tagName + &#39;Element&#39;;
    if (window[klass]) return window[klass];
    klass = &#39;HTML&#39; + tagName.capitalize() + &#39;Element&#39;;
    if (window[klass]) return window[klass];

    window[klass] = { };

&lt;span class=&quot;error&quot;&gt;// (GS) Does not provide any feature detection about the object.&lt;/span&gt;
    window[klass].prototype = document.createElement(tagName).__proto__;
    return window[klass];
  }

  if (F.ElementExtensions) {
    copy(Element.Methods, HTMLElement.prototype);
    copy(Element.Methods.Simulated, HTMLElement.prototype, true);
  }

  if (F.SpecificElementExtensions) {
    for (var tag in Element.Methods.ByTag) {
      var klass = findDOMClass(tag);
      if (Object.isUndefined(klass)) continue;
      copy(T[tag], klass.prototype);
    }
  }
&lt;/pre&gt;

&lt;p&gt;
The &lt;code&gt;findDOMClass&lt;/code&gt; assumes that the window will have an object based on &lt;code&gt;tagName&lt;/code&gt;
or that if this is not the case, then the element&#39;s &lt;code&gt;__proto__&lt;/code&gt; property will be readable. 
&lt;/p&gt;

&lt;p&gt;
There is no guarantee by any standard that there will be a &lt;code&gt;__proto__&lt;/code&gt; 
property present or what value it will hold, if any. 
&lt;/p&gt;

&lt;p&gt;
There is no guarantee by any standard of an &lt;code&gt;HTMLTableRowElement&lt;/code&gt; on window, nor any guarantee of what modifying its prototype will have. The library makes broad assumptions and performs no capability tests. 
&lt;/p&gt;

&lt;h4&gt;Replace the Host Environment&#39;s Element?&lt;/h4&gt;
&lt;p&gt;
    Not satisfied by altering over certain Host environments&#39; &lt;code&gt;Element&lt;/code&gt; 
    with its own properties,
    PrototypeJS seeks to create a constructor to replace those environments&#39; &lt;code&gt;Element&lt;/code&gt;
    with its own, copying over all &lt;em&gt;enumerable&lt;/em&gt; properties from the Host&#39;s &lt;code&gt;Element&lt;/code&gt;. 
    In Firefox, this includes all of &lt;code&gt;QueryInterface&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
    This creates the dilemma of having a debilitated Element. Where previously, in 
    Firefox, 
    &lt;code&gt;Element&lt;/code&gt; was native code, and &lt;code&gt;Element.prototype.TEXT_NODE&lt;/code&gt; had the value 
    &lt;code&gt;3&lt;/code&gt;, now, &lt;code&gt;Element&lt;/code&gt; is a PrototypeJS constructor function and 
    &lt;code&gt;Element.prototype.TEXT_NODE&lt;/code&gt; is undefined.
&lt;/p&gt;

&lt;pre&gt;
(function() {
  var element = this.Element;
  this.Element = function(tagName, attributes) {
    attributes = attributes || { };
    tagName = tagName.toLowerCase();
    var cache = Element.cache;
    if (Prototype.Browser.IE &amp;amp;&amp;amp; attributes.name) {
      tagName = &#39;&amp;lt;&#39; + tagName + &#39; name=&quot;&#39; + attributes.name + &#39;&quot;&amp;gt;&#39;;
      delete attributes.name;
      return Element.writeAttribute(document.createElement(tagName), attributes);
    }
    if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
    return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
  };
  Object.extend(this.Element, element || { });
}).call(window);

Element.cache = { };&lt;/pre&gt;
&lt;h4&gt;Event.extend - Don&#39;t do It!&lt;/h4&gt;
&lt;p&gt;The same approach is used here&lt;/p&gt;

&lt;pre&gt;
Event.extend = (function() {
  var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
    m[name] = Event.Methods[name].methodize();
    return m;
  });

  if (Prototype.Browser.IE) {
    Object.extend(methods, {
      stopPropagation: function() { this.cancelBubble = true },
      preventDefault:  function() { this.returnValue = false },
      inspect: function() { return &quot;[object Event]&quot; }
    });

    return function(event) {
      if (!event) return false;
      if (event._extendedByPrototype) return event;

      event._extendedByPrototype = Prototype.emptyFunction;
      var pointer = Event.pointer(event);
      Object.extend(event, {
        target: event.srcElement,
        relatedTarget: Event.relatedTarget(event),
        pageX:  pointer.x,
        pageY:  pointer.y
      });
      return Object.extend(event, methods);
    };

  } else {
  &lt;span class=&quot;error&quot;&gt;// (GS) Event.prototype is not guaranteed to be available in 
  // any browser.&lt;/span&gt;
    Event.prototype = Event.prototype || document.createEvent(&quot;HTMLEvents&quot;).__proto__;
    Object.extend(Event.prototype, methods);
    return Prototype.K;
  }
})();
&lt;/pre&gt;

&lt;h3&gt;Object.extend - Doesn&#39;t Account for JScript DontEnum Bug&lt;/h3&gt;
&lt;pre&gt;
Object.extend = function(destination, source) {
  for (var property in source)
&lt;span class=&quot;error&quot;&gt;// (GS) Does not account for JScript DontEnum bug.&lt;/span&gt;
    destination[property] = source[property];
  return destination;
};
&lt;/pre&gt;
&lt;p&gt;
    In IE, the keys of objects are skipped 
    &lt;a href=&quot;http://dhtmlkitchen.com/learn/js/enumeration/dontenum.jsp&quot;&gt;without properly checking the &lt;code&gt;DontEnum&lt;/code&gt; 
    flag&lt;/a&gt;. The skipped properties include
    the useful and often overridden &lt;code&gt;toString&lt;/code&gt; and &lt;code&gt;valueOf&lt;/code&gt;. 
    Special and careful considerations should be made to address this problem. 
&lt;/p&gt;

&lt;h3&gt;$A - Don&#39;t Rely on The Return Value of An Object&#39;s toString&lt;/h3&gt;
&lt;pre&gt;
if (Prototype.Browser.WebKit) {
  $A = function(iterable) {
    if (!iterable) return [];
&lt;span class=&quot;error&quot;
&gt;// (GS) Do not on the return value of an object&#39;s toString.&lt;/span&gt;
    if (!(Object.isFunction(iterable) &amp;amp;&amp;amp; iterable == &#39;[object NodeList]&#39;) &amp;amp;&amp;amp;
        iterable.toArray) return iterable.toArray();
    var length = iterable.length || 0, results = new Array(length);
    while (length--) results[length] = iterable[length];
    return results;
  };
}&lt;/pre&gt;

&lt;p&gt;
	A toString() with the return 
	value of &quot;[object NodeList]&quot; implies nothing else about the object 
	it was called on.
&lt;/p&gt;

&lt;h3&gt;The &lt;code&gt;readAttribute&lt;/code&gt; function, branched for Internet Explorer.&lt;/h3&gt;

&lt;h4&gt;Example&lt;/h4&gt;
&lt;p&gt;
Example page: &lt;a href=&quot;http://www.apple.com/itunes/&quot;&gt;http://www.apple.com/itunes/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
javascript:alert($(document.body).readAttribute(&quot;onload&quot;))
&lt;/p&gt;

&lt;p&gt;
Will result in partial string representation of a serialized function.
The string begins with &quot;)&quot;. 
&lt;/p&gt;

&lt;pre&gt;
_getEv: function(element, attribute) {
&lt;span class=&quot;error&quot;&gt;// (GS) Do not rely on function decompilation.&lt;/span&gt;
  var attribute = element.getAttribute(attribute);
&lt;span class=&quot;error&quot;&gt;// (GS) Do not prevent yourself from renaming a function.&lt;/span&gt;
&lt;span class=&quot;error&quot;&gt;// (GS) Broken - slice starts at wrong position.&lt;/span&gt;
  return attribute ? attribute.toString().slice(23, -2) : null;
},
&lt;/pre&gt;

&lt;p&gt;
    Function &lt;code&gt;readAttribute&lt;/code&gt; calls &lt;code&gt;getAttribute&lt;/code&gt; on the element. In Internet Explorer, 
    calling getAttribute always &lt;dfn&gt;reflects&lt;/dfn&gt; the property with the same name.
    In this case the property has the value of the function object, &lt;code&gt;loadShortcuts&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
    It isn&#39;t clear why the substring of 23 should be taken from the function&#39;s source code.
    The approach 
    of relying on the toString of an object defined elsewhere in the code 
    makes it hard to rename that function.
&lt;/p&gt;

&lt;h3&gt;Ajax.Request - Add an Underscore?&lt;/h3&gt;
&lt;p&gt;

&lt;/p&gt;
&lt;pre&gt;
  request: function(url) {
    this.url = url;
    this.method = this.options.method;
    var params = Object.clone(this.options.parameters);

    if (![&#39;get&#39;, &#39;post&#39;].include(this.method)) {
      // simulate other verbs over post
      params[&#39;_method&#39;] = this.method;
      this.method = &#39;post&#39;;
    }

    this.parameters = params;

    if (params = Object.toQueryString(params)) {
      // when GET, append parameters to URL
      if (this.method == &#39;get&#39;)
        this.url += (this.url.include(&#39;?&#39;) ? &#39;&amp;amp;&#39; : &#39;?&#39;) + params;

&lt;span class=&quot;error&quot;&gt;// (GS) All browsers support properly-formatted URIs.&lt;/span&gt;
&lt;span class=&quot;error&quot;&gt;// (GS) Do not add extra &quot;_&quot; parameter for some browsers.&lt;/span&gt;
      else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
        params += &#39;&amp;amp;_=&#39;;
    }
&lt;/pre&gt;

&lt;h3&gt;Broken Unescaping of HTML Strings&lt;/h3&gt;
&lt;p&gt;
    PrototypeJS adds escapeHTML and unescapeHTML to &lt;code&gt;String.prototype&lt;/code&gt;. 
    The problem with this code was discussed quite some time ago on 
    comp.lang.javascript.
&lt;/p&gt;

&lt;pre&gt;
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
  escapeHTML: function() {
    return this.replace(/&amp;amp;/g,&#39;&amp;amp;amp;&#39;).replace(/&amp;lt;/g,&#39;&amp;amp;lt;&#39;).replace(/&amp;gt;/g,&#39;&amp;amp;gt;&#39;);
  },
  unescapeHTML: function() {
    return this.replace(/&amp;amp;amp;/g,&#39;&amp;amp;&#39;).replace(/&amp;amp;lt;/g,&#39;&amp;lt;&#39;).replace(/&amp;amp;gt;/g,&#39;&amp;gt;&#39;);
  }
});

&lt;span class=&quot;error&quot;&gt;// (GS) Do not use with for simple property assignment&lt;/span&gt;
with (String.prototype.escapeHTML) div.appendChild(text);
&lt;/pre&gt;

&lt;p&gt;
    The problem is that the escape character for entities is &amp;amp;. This will have the result in 
    browsers identifying as Webkit or MSIE of:-
&lt;/p&gt;
&lt;pre&gt;
    &lt;code&gt;&quot;&amp;amp;amp;lt;&quot;.unescapeHTML()&lt;/code&gt; to &quot;&amp;lt;&quot; 
&lt;/pre&gt;

&lt;p&gt;
    The with statement is not needed to provide a more compact approach:
&lt;/p&gt;
&lt;pre&gt;
&quot;&quot;.escapeHTML.div.appendChild(&quot;&quot;.escapeHTML.text);
&lt;/pre&gt;

&lt;h3&gt;Enumerable.include - Two Loops? Strict Equality, or Loose Equality?&lt;/h3&gt;

&lt;p&gt;
    Enumerable.include. This function returns true if the Enumerable contains the object.
&lt;/p&gt;

&lt;pre&gt;
  include: function(object) {

    // (GS) Call the indexOf method on the object.
    if (Object.isFunction(this.indexOf))
      if (this.indexOf(object) != -1) return true;
    &lt;span class=&quot;error&quot;&gt;// (GS) If not found, search again.&lt;/span&gt;
    var found = false;
    this.each(function(value) {
    &lt;span class=&quot;error&quot;&gt;// (GS) Should use strict equality, === &lt;/span&gt;
      if (value == object) {
        found = true;
        throw $break;
      }
    });
    return found;
  },
&lt;/pre&gt;

&lt;p&gt;
    Enumerable.include first calls &lt;code&gt;this.indexOf()&lt;/code&gt;, and if that returns false, the collection 
    is searched using a similar algorithm to &lt;code&gt;Array.prototype.indexOf&lt;/code&gt;, except not using 
    strict equality. This tactic results in the collection being looped over twice. Function 
    &lt;code&gt;each&lt;/code&gt; calls a function for each iteration. If non-strict equality is desired, then the strict equality check 
    that can result by calling &lt;code&gt;this.indexOf&lt;/code&gt; should be omitted. 
&lt;/p&gt;

&lt;p&gt;
    A plausible solution would be &lt;code&gt;return this.indexOf(object)&lt;/code&gt;, and include a 
    strict &lt;code&gt;===&lt;/code&gt; check if &lt;code&gt;indexOf&lt;/code&gt; were not a function.
&lt;/p&gt;

&lt;h3&gt;getDimensions - clientWidth != offsetWidth, And Don&#39;t Expect clientWidth to be non-zero in IE&lt;/h3&gt;
&lt;pre&gt;
  getDimensions: function(element) {
    element = $(element);
    var display = $(element).getStyle(&#39;display&#39;);
    if (display != &#39;none&#39; &amp;amp;&amp;amp; display != null) // Safari bug
      return {width: element.offsetWidth, height: element.offsetHeight};

    // All *Width and *Height properties give 0 on elements with display none,
    // so enable the element temporarily
    var els = element.style;
    var originalVisibility = els.visibility;
    var originalPosition = els.position;
    var originalDisplay = els.display;
    els.visibility = &#39;hidden&#39;;
    els.position = &#39;absolute&#39;;
    els.display = &#39;block&#39;;
    var originalWidth = element.clientWidth;
    var originalHeight = element.clientHeight;
    els.display = originalDisplay;
    els.position = originalPosition;
    els.visibility = originalVisibility;
&lt;span class=&quot;error&quot;&gt;// (GS) use offsetWidth/Height.&lt;/span&gt;
    return {width: originalWidth, height: originalHeight};
  },
&lt;/pre&gt;
&lt;p&gt;
    This method has the unique quality of being one of the only methods in PrototypeJS to 
    have a code comment.
&lt;/p&gt;
&lt;p&gt;
    The code tries to get the &lt;code&gt;offsetWidth&lt;/code&gt; and &lt;code&gt;offsetHeight&lt;/code&gt; 
    of the Element. If the element is not displayed,
    then these properties will be 0, and in that case, the function will display the element temporarily,
    then calculate its &lt;code&gt;&lt;em&gt;client&lt;/em&gt;Width&lt;/code&gt; - not the &lt;code&gt;offsetWidth&lt;/code&gt; before immediately 
    hiding it. This function can be expected to
    provide inconsistent results when the element&#39;s CSS &lt;code&gt;display&lt;/code&gt; is changing.
    What&#39;s worse: Unless the element has a CSS &lt;code&gt;width&lt;/code&gt;, the &lt;code&gt;clientWidth&lt;/code&gt; will be 0 in IE.
&lt;/p&gt;

&lt;h3&gt;Calculating Offsets&lt;/h3&gt;
&lt;p&gt;Finding an Element&#39;s position is hard.&lt;/p&gt;
&lt;p&gt;
  Calculating the position of an element requires adding the offsetTop/Left of 
  &lt;code&gt;offsetParent&lt;/code&gt;s, border offsets, 
  and scroll offsets of parentNodes.
&lt;/p&gt;

&lt;p&gt;
    A BODY with margin, position and/or border can affect the offsetTop/Left differently, depending
    on the browser.
    This is a harmful effect propagated by the 
    &lt;a href=&quot;http://www.w3.org/TR/cssom-view/#offset-attributes&quot;&gt;CSSOM Views&lt;/a&gt; standard. 
&lt;/p&gt;

&lt;h3&gt;cumulativeOffset&lt;/h3&gt;
&lt;p&gt;
    PrototypeJS misses both points and just adds offsetTop/Left.
&lt;/p&gt;

&lt;pre&gt;
  cumulativeOffset: function(element) {
    var valueT = 0, valueL = 0;
    do {
      valueT += element.offsetTop  || 0;
      valueL += element.offsetLeft || 0;
      element = element.offsetParent;
    } while (element);
    &lt;span class=&quot;error&quot;&gt;// (GS) Don&#39;t call a function that returns an 
    // Array with top and left properties.
    // Better just return an Array or an Object.&lt;/span&gt;
    return Element._returnOffset(valueL, valueT);
  },
&lt;/pre&gt;

&lt;p&gt;
    The seriousness of the problem is apparent when precision is crucial and off by a pixel or more would be failure, 
    (e.g. make element to overlap another element exactly, activate a drop zone). 
&lt;/p&gt;

&lt;p&gt;
    The bug also exists in &lt;code&gt;positionedOffset&lt;/code&gt; and affects every function that uses 
    either function, including &lt;code&gt;within&lt;/code&gt;, &lt;code&gt;scrollTo&lt;/code&gt;, and all the functions 
    that call those functions, such as others found in Scriptaculous (dragdrop.js, effects.js).
&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
    A few core parts of PrototypeJS exhibiting some serious bugs. 
    There are many more issues, such as &lt;code&gt;Hash&lt;/code&gt;,  
    but this entry is already getting excessively long. 
&lt;/p&gt;

&lt;p&gt;
    PrototypeJS is designed in a non-standard way around the modification of host objects. The code 
    that exists is complicated and not very efficient. I cannot recommend using this library 
    for anything.
&lt;/p&gt;
</description>
	    <dc:date>2008-06-17T01:37:59-05:00</dc:date>
	        </item>
            <item rdf:about="http://dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok">
	    <title>JavaScript Trends</title>
	    <link>http://dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok</link>
        <description>&lt;p&gt;I came across a &lt;a href=&quot;http://alex.dojotoolkit.org/?p=535&quot;&gt;blog post&lt;/a&gt; yesterday that had  
a lot of misinformation. The post had received several comments and trackbacks thanking and commending the author 
for his &quot;helpful&quot; post. At first I was mad. &quot;How can these people give this guy credit for 
misinformation,&quot; I thought. I wrote up a comment correcting 
on various points, intending to publish it on the author&#39;s blog.
&lt;/p&gt;

&lt;p&gt;
Thankfully, my comment could not be posted due to some problem with the weblog. I am thankful of this because
I ended up thinking about the problem on a greater depth.
&lt;/p&gt;

&lt;p&gt;
I decided to respond here, providing a review below. I was more bothered by the phenomenon
of people eager to learn misinformation. The more I thought about that phenomenon, the more I realized that it&#39;s 
not the author&#39;s fault, it&#39;s just the way things are. I discovered a part of the web that I want to change.
&lt;/p&gt;

&lt;p&gt;
The expert, in this case, is Alex Russell, of Dojo fame, as 
&lt;a href=&quot;http://ajaxian.com/archives/javascript-idioms-you-need-to-know&quot;
&gt;Ajaxian likes to call it&lt;/a&gt;. It doesn&#39;t really matter who it is. In fact, it could have been me
several years ago, when my JavaScript knowlegde was not as strong. I have written 
some really awful javascript that fortunately did not become famous. 
&lt;/p&gt;

&lt;p&gt;
My initial technical responses to the blog entry, which I have cut and snipped, are interspersed below. I have done 
my best to not take the author out of context and provide clear, relevant feedback. My real &quot;response&quot; starts below the
proceeding technical response.
&lt;/p&gt;

&lt;h3&gt;Technical Response&lt;/h3&gt;
&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
Everything in JavaScript is an Object. Even functions 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Not true. 
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact: &lt;/strong&gt;
There are primitive values, too: undefined, null, true, 3, and &quot;foo&quot; are all primitive values. Not objects.
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
Every object is always mutable 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
&lt;strong&gt;Fact: &lt;/strong&gt;
An EcmaScript object itself is always mutable, 
but property-setting will not be always successful and error-free. 
&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;
        &lt;p&gt;
        Host objects do not need to implement setters for each property. 
        For purpose of providing a relevant example to back up my claim:  
        &lt;/p&gt;
       &lt;pre&gt;
function fixEvent(e) {
  e=e||event;
  e.pageX = 1; // getEventPageX(e);
}&lt;/pre&gt;
        &lt;p&gt;
        - will cause an error in Firefox. The &lt;code&gt;pageX&lt;/code&gt; property actually needs a patch,  
        because creating events, the 
        &lt;code&gt;pageX&lt;/code&gt; property doesn&#39;t get set correctly 
        (&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=411031&quot;&gt;bug 411031&lt;/a&gt;). So the argument 
        &quot;every object is always mutable&quot; leads to developers doing things like writing a 
        &lt;a href=&quot;http://api.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.fixEvent&quot;&gt;&quot;fixEvent&quot; function&lt;/a&gt;. It is not safe to do so.
        &lt;/p&gt;
        
        &lt;/li&gt;
        &lt;li&gt;
            Some properties are tagged ReadOnly. A String or Function object&#39;s length property, for example.
        &lt;/li&gt;
    &lt;/ol&gt;
&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
The dot operator is equivalent to de-referencing by hash (e.g., foo.bar === foo[&quot;bar&quot;]) 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; The two &lt;dfn&gt;property access&lt;/dfn&gt; operators &lt;code&gt;.&lt;var&gt;&amp;lt;Identifier&amp;gt;&lt;/var&gt;&lt;/code&gt; and &lt;code&gt;[&lt;var&gt;&amp;lt;identifier-string&amp;gt;&lt;/var&gt;]&lt;/code&gt; perform identical operations.
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
The new keyword creates an object that class 
constructors run inside of, thereby 
imprinting them 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;False.&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact: &lt;/strong&gt;
There are no class constructors. No classes in the current release of EcmaScript 262 r3.
&lt;/p&gt;

&lt;p&gt;The new operator (an operator) creates a new object in context of the function on which its called. 
Nothing gets imprinted. 
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
Functions are always closures (combine w/ 
previous rule to create OOP) 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
If used very carefully, closures can be used to mimic some of the constructs found in OO languages.
However, to say that closures &quot;create OOP&quot; is false and misleading.
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
The this keyword is relative to the
execution context, not the declaration context 
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
There is no &quot;declaration context&quot;. You seem to have made this up as a way
to describe the way you think JavaScript works. 
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
The prototype property is mutable
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Not informative.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; A property is a reference. 
&lt;/p&gt;

&lt;p&gt;
If the property&#39;s value is a native EcmaScript object, then it will be mutable. 
It goes without saying that this is true even if the name of the property is &lt;code&gt;prototype&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Considering a prototype property of a function, where the prototype&#39;s value is an EcmaScript object: &lt;code&gt;{}&lt;/code&gt;, then 
it is mutable (as discussed above).
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex:&lt;/h5&gt;
&lt;p&gt;
Jeremy: great clarifications. Thanks.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Jeremey provided a false statement with code that was confusing. Jeremey wrote:
&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre&gt;
y = new Foo();
assert(y.gimme() == 2);
&lt;/pre&gt;

&lt;p&gt;But:&lt;/p&gt;
&lt;p&gt;
button.onclick = &quot;alert(y.gimme())&quot; will error rather than alerting &quot;2&quot;, because in an event handler, &quot;this&quot; refers to the elm which sourced the event.
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; This is a perfectly valid assignment of a string value to an &lt;code&gt;onclick&lt;/code&gt; property of a &lt;code&gt;button&lt;/code&gt; object. 
&lt;/p&gt;

&lt;p&gt;
Jeremy&#39;s example of a button object with an onclick property assigned to a string value:-
&lt;/p&gt;
&lt;pre&gt;button.onclick = &quot;alert(y.gimme())&quot;&lt;/pre&gt;
&lt;p&gt;
- the string &lt;code&gt;&quot;alert(y.gimme())&quot;&lt;/code&gt; is not &lt;code&gt;eval&lt;/code&gt;&#39;d.
&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;small&gt;(Continuing Jeremy&#39;s post)&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;
because in an event handler, &quot;this&quot; refers to the elm which sourced the event.
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
Has relevant meaning in a script:-
&lt;/p&gt;
&lt;pre&gt;
// assign function to onclick.
button.onclick = y.gimme;&lt;/pre&gt; 
&lt;p&gt;
Definitely not in:
&lt;/p&gt;

&lt;pre&gt;
&amp;lt;body&amp;gt;
&amp;lt;script&amp;gt;

function Foo() {
this.x = 1;

this.gimme = function() {
return this.x + 1;
}
}

y = new Foo();
&amp;lt;/script&amp;gt;

&amp;lt;button onclick=&quot;alert(y.gimme())&quot;&amp;gt;click me&amp;lt;/button&amp;gt;

&amp;lt;/body&amp;gt;
&lt;/pre&gt;
&lt;h5&gt;Result&lt;/h5&gt;
&lt;p&gt;
    When the button is clicked, the method &lt;code&gt;gimme&lt;/code&gt; is called with &lt;code&gt;y&lt;/code&gt; as the thisArg. The number is 
    returned and displayed as a string in the alert box.
&lt;/p&gt;

&lt;p&gt;
Thanking Jeremy for Jeremy&#39;s mistake and calling the mistake a clarification does not make Jeremy correct. 
It is not helpful to Jeremy or anyone else. 
&lt;/p&gt;

&lt;blockquote&gt;
&lt;h5&gt;alex: (To Dethe):&lt;/h5&gt;
&lt;p&gt;
My statement about objects (variables whose .constructor property in some way descends from Object) was correct.
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; No, it was not correct. Now you&#39;ve made another misstatement.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; &lt;code&gt;(new function(){})&lt;/code&gt; - is an object, not a variable. Its - constructor - property doesn&#39;t &quot;descend&quot; from 
Object, either. 
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; &lt;code&gt;var i = 0, len;&lt;/code&gt; - is an example of two variables that do not have a &lt;code&gt;.constructor&lt;/code&gt; property.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; The term &quot;descend&quot; has no meaning in context of describing a constructor property; it is
fictitious terminology to describe the way you imagine JavaScript works. 
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;small&gt;(alex: To Dethe, continued):&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;
Also, the hash deference is exactly equivalent. That there&#39;s no way to have a 
JS lexer handle an variable name with spaces in it in no way detracts from the equivalence, 
it just means that the dot operator has to follow the rules of thing that aren&#39;t string literals.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; There is no &quot;dot operator.&quot; 
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; The fullstop, &quot;.&quot; also has meaning in numbers, for example, &lt;code&gt;4.2.toString()&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Fact:&lt;/strong&gt; There are two property access operators: &quot;.&quot; and &quot;[]&quot;. 
There are many &quot;things that are not string literals.&quot; The &quot;.&quot; property access operator can be used only for valid identifiers. 
&lt;/p&gt;

&lt;p&gt;
I think you were using the term &quot;de-reference&quot; to try to describe getting a value. Now your using 
&quot;deference&quot;. I&#39;m not sure what to make of that.
&lt;/p&gt;


&lt;h3&gt;The Real &quot;Response&quot;&lt;/h3&gt;
&lt;p&gt;
 My real &quot;response&quot; in the larger sense, is that I&#39;m taking a stance. I&#39;m going to try and change the web. 
&lt;/p&gt;

&lt;h4&gt;Think 2.0&lt;/h4&gt;
&lt;p&gt;
A who&#39;s-who in web 2.0 is destructive to the web, in a way. The idea should win, 
not the individual. The popular libraries have 
spread ideas for web development across the web but they have also played a big 
part in the &quot;whos-who&quot; trend that I see.
&lt;/p&gt;

&lt;p&gt;
What I see demonstrated in the blog entry that I replied to is a 
misunderstaning of JavaScript that received positive acknowledgement and review. The question is: Why? 
Is it because the entry is simple and clear? 
&lt;/p&gt;

&lt;h4&gt;Ask Why&lt;/h4&gt;
&lt;p&gt;
If a &quot;famed&quot; individual can  be commended for teaching JavaScript facts that are 
false and inaccurate, what does that say about what web developers value in the web? Where are we headed? 
I am hoping that this trend will reverse itself. The reversal of this trend starts by questioning things.
I question things and you should, too.
&lt;/p&gt;

&lt;h3&gt;Angry, Bitter, and Vile?&lt;/h3&gt;
&lt;p&gt;
 As much as I&#39;ve pointed out bad parts of Dojo and Google (And jQuery and PrototypeJS and YUI), 
 I probably sound like a bitter, angry person. In fact, there are people who would love to have you believe that I 
 am nothing more than that. I&#39;ve made my observations and shared them, even at the expense of sounding 
 mean and bitter. 
 I want the web to change, and in my next entry, I&#39;ll clearly explain the direction I want the web to turn.
&lt;/p&gt;

</description>
	    <dc:date>2008-05-30T13:53:28-05:00</dc:date>
	        </item>
    
</rdf:RDF>
