<?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://www.dhtmlkitchen.com/news/default">
		<title>DHTML Kitchen News</title>
		<link>http://www.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>2008-07-04T02:36:21-05:00</dc:date>
		<dc:language>en</dc:language>

        <items>
        <rdf:Seq>
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/07/04/Find-Element-Position" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/06/17/Prototype-js-A-Review" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/05/22/Gmail-Latest-News-from-the-GMail-Blog" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/05/11/Decorator-Factory-Aspect" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/05/06/The-JavaScript-Guru" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/05/05/APE-JavaScript-Library" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/04/19/Testing-JavaScript" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/02/21/Load-Time-Constants-Part-I" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/02/01/Google-Code-in-Safari" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/01/31/Crashed" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2008/01/04/Event-Notification-System" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2007/11/24/Browser-Detection" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2007/11/08/Opera-Bug-getComputedStyle-Returns-Margin-for-Unset-Top-Left-Values" />
                                <rdf:li rdf:resource="http://www.dhtmlkitchen.com/news/default/2007/10/21/Iteration-Enumeration-Primitives-and-Objects" />
                </rdf:Seq>
        </items>
    </channel>

            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/07/04/Find-Element-Position">
	    <title>Find Element Position</title>
	    <link>http://www.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://www.dhtmlkitchen.com/news/default/2008/06/17/Prototype-js-A-Review">
	    <title>Prototype.js - A Review</title>
	    <link>http://www.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; attributes.name) {
      tagName = &#39;&lt;&#39; + tagName + &#39; name=&quot;&#39; + attributes.name + &#39;&quot;&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; 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://www.dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok">
	    <title>JavaScript Trends</title>
	    <link>http://www.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>
	                                <wfw:comment>http://www.dhtmlkitchen.com/commentapi/default/uncategorized/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok</wfw:comment>
            <wfw:commentRss>http://www.dhtmlkitchen.com/news/default/2008/05/30/JavaScript-Idioms-Every-Webdev-Should-Grok?page=comments&amp;flavor=rss2</wfw:commentRss>
            </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/05/22/Gmail-Latest-News-from-the-GMail-Blog">
	    <title>Gmail: Latest News from the GMail Blog</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/05/22/Gmail-Latest-News-from-the-GMail-Blog</link>
        <description>&lt;p&gt;
There is a new feature on the GMail login page: 
&lt;cite&gt;&lt;strong&gt;Gmail: Latest News from the GMail Blog&lt;/strong&gt;&lt;/cite&gt;.
&lt;/p&gt;
&lt;p&gt;
I first noticed this last month when the GMail login page was reacting very slowly. 
The page froze for about 6 seconds in Firefox. I noticed 
the missing content in the lower left corner of the page appear immediately before the page 
unfroze, allowing me to then enter in my login credentials.
&lt;/p&gt;

&lt;p&gt;
The latest &lt;cite&gt;News from the GMail Blog&lt;/cite&gt; update is:
&lt;/p&gt;
&lt;blockquote&gt;
&lt;h5&gt;&lt;a href=&quot;http://gmailblog.blogspot.com/2008/05/need-for-speed-path-to-faster-loading.html&quot;
&gt;A need for speed: the path to a faster loading sequence&lt;/a&gt;&lt;/h5&gt;
&lt;p&gt;Posted May 13, 2008&lt;/p&gt;
&lt;p&gt;Great performance has always been an obsession at Google and it&#39;s something that we think about and work on everyday. We...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
The &lt;a href=&quot;http://gmailblog.blogspot.com/2008/05/need-for-speed-path-to-faster-loading.html&quot;&gt;GMail blog&lt;/a&gt; 
talks about how the GMail team worked to
&lt;q&gt;&lt;cite&gt;reduce the number of overall requests, make more of the requests cacheable by the browser, 
and reduce the overhead of each request.&lt;/cite&gt;&lt;/q&gt; 
&lt;/p&gt;

&lt;h4&gt;HTML Source&lt;/h4&gt;
&lt;p&gt;
The &lt;em&gt;HTML&lt;/em&gt; source code of the GMail login page contradicts that with:
&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;three external &lt;code&gt;script&lt;/code&gt; tags, loaded over a secure connection
	&lt;/li&gt;
	&lt;li&gt;fourteen &lt;code&gt;img&lt;/code&gt; tags&lt;/li&gt;
	&lt;li&gt;
	&lt;em&gt;twelve&lt;/em&gt; inline &lt;code&gt;script&lt;/code&gt; tags, 
	&lt;/li&gt;
	&lt;li&gt;
	four inline &lt;code&gt;style&lt;/code&gt; tags, inline style attributes. 
	&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  One of the external script tags is duplicated, but with a different query string, so even though the 
  response is the same &lt;code&gt;DetectBrowser&lt;/code&gt; code, it is &lt;em&gt;un&lt;/em&gt;-cacheable and downloaded &lt;em&gt;twice&lt;/em&gt;
  (bug).
&lt;/p&gt;

&lt;p&gt;
  Two of the script tags (&lt;a href=&quot;https://ssl.google-analytics.com/urchin.js&quot;&gt;urchin.js&lt;/a&gt;, inline) 
  use javascript to &lt;code&gt;document.write&lt;/code&gt; &lt;em&gt;more&lt;/em&gt; external 
  script and image tags. 
&lt;/p&gt;

&lt;p&gt;
This is all beautifully 
wrapped up in a nested, &lt;a href=&quot;http://www.w3.org/TR/CSS21/tables.html#auto-table-layout&quot;
&gt;automatic&lt;/a&gt; table layout (not &lt;a href=&quot;http://www.w3.org/TR/CSS21/tables.html#fixed-table-layout&quot;&gt;fixed&lt;/a&gt;).
&lt;/p&gt;

&lt;h4&gt;Biggest Bottleneck&lt;/h4&gt;
&lt;p&gt;
Despite the resource problems, the &lt;cite&gt;News from the GMail Blog&lt;/cite&gt; on the GMail login page 
appears to
freeze Firefox for roughly 1-6 seconds, depending on latency and connection speed.
&lt;/p&gt;

&lt;p&gt;
 This feature is slow because the page isn&#39;t completely rendered until the 
 &lt;a href=&quot;https://www.blogger.com/feeds/6781693/posts/default?alt=json-in-script&amp;callback=build_posts&amp;max-results=1&amp;orderby=published&quot;&gt;external JSON&lt;/a&gt; is downloaded, 
 then transformed to HTML, then rendered on the page.
&lt;/p&gt;

&lt;h4&gt;Solution?&lt;/h4&gt;
&lt;p&gt;
&lt;cite&gt;News from the GMail Blog&lt;/cite&gt; should be included in the server response for the login page, as HTML 
(if it is to be included at all). 
&lt;/p&gt;

&lt;p&gt;
Blog entries about acheivements are useful when they are informative and specific. This:
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
To do this, we used a lot of different web development tools, like Httpwatch, WireShark, and Fiddler, 
plus our own performance measuring systems
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Comes off as a bit self-aggrandizing; especially in contrast to the source code of the GMail login page.
&lt;/p&gt;
</description>
	    <dc:date>2008-05-22T14:40:22-05:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/05/11/Decorator-Factory-Aspect">
	    <title>Factory Aspect, Added to a Decorator: APE.getById</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/05/11/Decorator-Factory-Aspect</link>
        <description>&lt;p&gt;
    This article describes the generic concepts for creating and mixing design patterns. 
    The basic principle for all design patterns is: &lt;em&gt;Encapsulate the parts that vary&lt;/em&gt;. 
&lt;/p&gt;

&lt;p&gt;
    The problem is finding a way to create a generic &lt;dfn&gt;Factory&lt;/dfn&gt; that can be reused on 
    various constructor functions for element &lt;dfn&gt;Decorators&lt;/dfn&gt;. This article explains 
    the problem and the process for finding the solution. 
&lt;/p&gt;

&lt;h3&gt;Decorator Factory Aspect&lt;/h3&gt;
&lt;p&gt;A &lt;dfn&gt;Decorator Factory Aspect&lt;/dfn&gt; is a 
&lt;dfn&gt;Factory method&lt;/dfn&gt;, added as an &lt;dfn&gt;Aspect&lt;/dfn&gt; to a constructor of a &lt;dfn&gt;Decorator&lt;/dfn&gt;.&lt;/p&gt;

&lt;p&gt;Before I explain how to add a &lt;dfn&gt;Factory&lt;/dfn&gt; to a constructor function for an element &lt;dfn&gt;decorator&lt;/dfn&gt;,
I should first define &lt;dfn&gt;Decorator&lt;/dfn&gt; (also called a &lt;dfn&gt;wrapper&lt;/dfn&gt;), &lt;dfn&gt;Factory&lt;/dfn&gt; and &lt;dfn&gt;Aspect&lt;/dfn&gt;. 
&lt;/p&gt;

&lt;dl&gt;
    &lt;dt&gt;Decorator Pattern&lt;/dt&gt;
    &lt;dd&gt;makes it possible to extend (decorate) the functionality of a class 
    by adding a new decorator class that wraps the original class. 
    (&lt;a
        href=&quot;http://en.wikipedia.org/wiki/Decorator_pattern&quot;&gt;Wikipedia link&lt;/a&gt;)
    &lt;/dd&gt;
    
    &lt;dt&gt;Factory Pattern&lt;/dt&gt;
    &lt;dd&gt;
        The Factory pattern is a creational design pattern 
        that encapsulates the processes of creating objects
    (&lt;a
        href=&quot;http://en.wikipedia.org/wiki/Factory_pattern&quot;&gt;Wikipedia link&lt;/a&gt;)
    &lt;/dd&gt;

    &lt;dt&gt;Aspect&lt;/dt&gt;
    &lt;dd&gt;
        &lt;cite&gt;&lt;q&gt;introduces separation of concerns, specifically cross-cutting concerns, as an advance in modularization&lt;/q&gt;&lt;/cite&gt; 
        (&lt;a
        href=&quot;http://en.wikipedia.org/wiki/Aspect-oriented_programming&quot;&gt;Wikipedia link&lt;/a&gt;)
    &lt;/dd&gt;
&lt;/dl&gt;

&lt;h4&gt;Decorator Examples&lt;/h4&gt;
&lt;p&gt;
  &lt;dfn&gt;Decorator&lt;/dfn&gt; is very common in JavaScript. For example: &lt;a href=&quot;http://developer.yahoo.com/yui/docs/Element.js.html&quot;&gt;YAHOO.util.Element&lt;/a&gt; &lt;dfn&gt;decorates&lt;/dfn&gt; an element, 
  jQuery &lt;dfn&gt;decorates&lt;/dfn&gt; an array of elements. 
&lt;/p&gt;

&lt;h4&gt;Factory Example&lt;/h4&gt;

&lt;p&gt;The &lt;dfn&gt;Factory&lt;/dfn&gt; gets or creates a &lt;dfn&gt;decorated&lt;/dfn&gt; element. 
The &lt;code&gt;id&lt;/code&gt; of the &lt;dfn&gt;wrapper&lt;/dfn&gt; is the same as the &lt;code&gt;id&lt;/code&gt; of the element. 
This is the part I want to make reusable:&lt;/p&gt;
&lt;pre&gt;
/**
 * @constructor
 * @param {String} id - the id of the element and widget. 
 */
function ElementWrapper(id, x) {
  this.id = id;
  this.x = x;
}

&lt;span class=&quot;comment&quot;&gt;// Factory. 
// &lt;span class=&quot;todo&quot;&gt;TODO:&lt;/span&gt; How can I make this generic/reusable?&lt;/span&gt;
ElementWrapper&lt;span style=&quot;color: #191; background: #FFFFc9&quot;&gt;.instances = {};&lt;/span&gt;
ElementWrapper&lt;span style=&quot;color: #191; background: #FFFFc9&quot;&gt;.getById = &lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;var&gt;id&lt;/var&gt;, &lt;var&gt;x&lt;/var&gt;) {
  &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.instances.hasOwnProperty(&lt;var&gt;id&lt;/var&gt;)} &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.instances[&lt;var&gt;id&lt;/var&gt;];
  &lt;span class=&quot;keyword&quot;&gt;return this&lt;/span&gt;.instances[&lt;var&gt;id&lt;/var&gt;] = &lt;span class=&quot;keyword&quot;&gt;new this&lt;/span&gt;(&lt;var&gt;id&lt;/var&gt;, &lt;var&gt;x&lt;/var&gt;);
};&lt;/span&gt;

ElementWrapper.prototype = { 
  show : function() { 
    document.getElementById(this.id).style.visibility = &quot;visible&quot;;
  }
};
&lt;/pre&gt;

&lt;h5&gt;Benefits&lt;/h5&gt;
&lt;p&gt;
    Solves the problem of creating only one decorator per element &lt;code&gt;id&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
By calling &lt;code&gt;getElementById&lt;/code&gt;, the &lt;dfn&gt;decorator&lt;/dfn&gt; can avoid 
some of the problems with changing node references with &lt;code&gt;innerHTML&lt;/code&gt; (though state changes 
must still be managed manually).
&lt;/p&gt;

&lt;h3&gt;
  Problem: &lt;abbr title=&quot;Dont Repeat Yourself&quot;&gt;DRY&lt;/abbr&gt;
&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Don&#39;t Repeat Yourself&lt;/p&gt;
&lt;p&gt;
    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
  It is cumbersome and error-prone to write out a &lt;dfn&gt;Factory&lt;/dfn&gt; each time. 
Since this is an idiom I use a lot, it makes 
  sense to make it reusable.&lt;/p&gt;

&lt;p&gt;
    I want to have a generic &lt;code&gt;getById&lt;/code&gt; method that can be reused and will return 
    an instance of the constructor that it is called on. I want to be able to pass 
    extra arguments to that constructor (varargs). 
&lt;/p&gt;

&lt;h3&gt;Encapsulate the Parts That Vary&lt;/h3&gt;
&lt;p&gt;
&lt;strong&gt;What varies?&lt;/strong&gt; 
&lt;/p&gt;

&lt;p&gt;
  The &lt;code&gt;id&lt;/code&gt; parameter variable of &lt;code&gt;getById&lt;/code&gt; does not change; it will 
  always be present in any generic &lt;dfn&gt;Factory&lt;/dfn&gt;. 
  The parts of the &lt;dfn&gt;Factory&lt;/dfn&gt; that vary are: The additional zero or more arguments (varargs, 
  this case, &lt;code&gt;x&lt;/code&gt;),
  and the context, or &lt;dfn&gt;thisArg&lt;/dfn&gt;.
&lt;/p&gt;

&lt;p&gt;
    Resolving the context arg is easy. 
&lt;/p&gt;

&lt;p&gt;
  If I can solve passing varargs to a constructor in a generic context, 
  it will be possible to create a generic &lt;dfn&gt;Factory&lt;/dfn&gt; &lt;dfn&gt;Aspect&lt;/dfn&gt;. 
&lt;/p&gt;

&lt;h4&gt;Function newApply&lt;/h4&gt;
A way to call &lt;code&gt;new&lt;/code&gt; with variable arguments would solve this problem.
A &lt;code&gt;new + apply()&lt;/code&gt; would provide the varargs functionality of &lt;code&gt;apply&lt;/code&gt;, 
but passed to &lt;code&gt;[[Construct]]&lt;/code&gt;, not &lt;code&gt;[[Call]]&lt;/code&gt;. 

&lt;p&gt;This has been solved in &lt;a href=&quot;/ape&quot; title=&quot;AOP Pointcuts for JavaScript&quot;&gt;APE&lt;/a&gt; core. 
The source code for &lt;code&gt;APE.newApply&lt;/code&gt;:
&lt;/p&gt;
&lt;pre&gt;&lt;span class=&quot;comment&quot;&gt;
/** 
 * @param {Function} fun constructor to be invoked.
 * @param {Array} args arguments to pass to the constructor.
 * Instantiates a constructor and uses apply().
 */&lt;/span&gt;
newApply : &lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;var&gt;fun&lt;/var&gt;, &lt;var&gt;args&lt;/var&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;(arguments.length === 0) &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;;
    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; &lt;var&gt;f&lt;/var&gt; = arguments.callee, &lt;var&gt;i&lt;/var&gt;;

    &lt;var&gt;f&lt;/var&gt;.prototype = &lt;var&gt;fun&lt;/var&gt;.prototype; // Add prototype.
    &lt;var&gt;f&lt;/var&gt;.prototype.constructor = &lt;var&gt;fun&lt;/var&gt;;

    &lt;var&gt;i&lt;/var&gt; = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; &lt;var&gt;f&lt;/var&gt;;
    fun.apply(&lt;var&gt;i&lt;/var&gt;, &lt;var&gt;args&lt;/var&gt;);  &lt;span class=&quot;comment&quot;&gt;// Apply the original constructor.&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;var&gt;i&lt;/var&gt;;
}
&lt;/pre&gt;

&lt;h4&gt;What&#39;s it Good For?&lt;/h4&gt;
&lt;p&gt;
  Now I can create the generic &lt;code&gt;getById&lt;/code&gt; function I wanted. This function can be added as an &lt;dfn&gt;aspect&lt;/dfn&gt; 
  to any constructor function. &lt;dfn&gt;Factory&lt;/dfn&gt; &lt;dfn&gt;Aspect&lt;/dfn&gt; &lt;code&gt;APE.getById&lt;/code&gt; is a part of 
  &lt;code title=&quot;AOP Pointcuts for EcmaScript&quot;&gt;APE&lt;/code&gt; core. 
&lt;/p&gt;

&lt;pre&gt;
getById : &lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;var&gt;id&lt;/var&gt;) {
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;(!&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.hasOwnProperty(&lt;span class=&quot;q&quot;&gt;&quot;instances&quot;&lt;/span&gt;)) &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.instances = {};
    &lt;span class=&quot;keyword&quot;&gt;return this&lt;/span&gt;.instances[&lt;var&gt;id&lt;/var&gt;] || (&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.instances[&lt;var&gt;id&lt;/var&gt;] = APE.newApply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, arguments));       
},
&lt;/pre&gt;

&lt;h4&gt;Using the Generic &lt;code&gt;getById&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;This &lt;code&gt;getById&lt;/code&gt; method can be used with &lt;code&gt;ElementWrapper&lt;/code&gt; (above) 
or any other constructor that acts as a &lt;dfn&gt;Decorator&lt;/dfn&gt; to an element and 
accepts the element&#39;s &lt;code&gt;id&lt;/code&gt; as its first argument.
&lt;/p&gt;
&lt;pre&gt;
Slider = function(&lt;var&gt;id&lt;/var&gt;, &lt;var&gt;dir&lt;/var&gt;) { &lt;span class=&quot;comment&quot;&gt;/* ... */&lt;/span&gt; };

// Factory. 
&lt;span style=&quot;color:#191; background: #FFFFc9&quot;&gt;Slider.getById = APE.getById;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;
    Then I can use:
&lt;/p&gt;
&lt;pre&gt;
Slider.getById( &quot;weight&quot;, 1 );
&lt;/pre&gt;
&lt;p&gt;
Subsequent calls to:&lt;/p&gt;
&lt;pre&gt;
Slider.getById( &quot;weight&quot; );
&lt;/pre&gt;

&lt;p&gt;&amp;mdash; will return the same &lt;code&gt;Slider&lt;/code&gt; instance.&lt;/p&gt;

&lt;h3&gt;More Examples&lt;/h3&gt;

&lt;p&gt;I have used this approach for many parts of &lt;a title=&quot;AOP Pointcuts for EcmaScript&quot; href=&quot;/ape/&quot;&gt;APE&lt;/a&gt;, including &lt;a href=&quot;/ape/example/widget/calendar/&quot;&gt;Calendar&lt;/a&gt;,
&lt;a href=&quot;/ape/example/drag/&quot;&gt;Draggable, and Slider&lt;/a&gt;. It is most useful for building widgets.&lt;/p&gt;

&lt;h3&gt;Reusable Concept&lt;/h3&gt;
&lt;p&gt;Another closely related technique is &lt;dfn&gt;Decorator&lt;/dfn&gt; that accepts an &lt;em&gt;element&lt;/em&gt; instead 
of an element&#39;s &lt;code&gt;id&lt;/code&gt;. This is covered by &lt;code&gt;APE.getByNode&lt;/code&gt;.
&lt;/p&gt;

&lt;h3&gt;Source Code&lt;/h3&gt;
&lt;p&gt;
  &lt;a href=&quot;/ape/build/APE.js&quot; title=&quot;APE Library Core JavaScript&quot;&gt;APE.js&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;Reflection&lt;/h3&gt;
&lt;p&gt;
In most patterns, encapsulating the parts that vary entails creating an class. 
However, in JavaScript, this particular pattern was simple to implement by using just 
two functions (&lt;code&gt;APE.getById&lt;/code&gt; and &lt;code&gt;APE.newApply&lt;/code&gt;) and leveraging the dynamic nature of 
JavaScript.
&lt;/p&gt;

&lt;h3&gt;Forward to ES4&lt;/h3&gt;
&lt;p&gt;
  ES4 has had some proposals for something called a &lt;dfn&gt;splat&lt;/dfn&gt; operator.
&lt;/p&gt;
&lt;pre&gt;
fun(...argsOrArray); 
new fun(...argsOrArray);
&lt;/pre&gt;

&lt;p&gt;This proposal will allow passing varargs to a constructor or a function call.&lt;/p&gt;

&lt;p&gt;It is unclear how the &lt;dfn&gt;splat&lt;/dfn&gt; operator, if accepted into the language, will work with 
functions which expect typed arguments, in strict mode. 
&lt;/p&gt;

&lt;h3&gt;Links&lt;/h3&gt;
&lt;p&gt;
&lt;a href=&quot;http://www.artima.com/intv/dry.html&quot;&gt;Orthogonality and the DRY Principle&lt;/a&gt;,
A Conversation with Andy Hunt and Dave Thomas, Part II
by Bill Venners
March 10, 2003
&lt;/p&gt;
</description>
	    <dc:date>2008-05-11T22:35:46-05:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/05/06/The-JavaScript-Guru">
	    <title>The JavaScript Guru</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/05/06/The-JavaScript-Guru</link>
        <description>&lt;p&gt;
Programming is not &quot;wizardry.&quot; I am not a &quot;JavaScript Ninja&quot; or an &quot;Ajax Guru.&quot; 
&lt;/p&gt;

&lt;h3&gt;What, no Sword?&lt;/h3&gt;
&lt;p&gt;
Programming is a scientific discipline. It requires zero mystical powers (although I have been known to &quot;disappear&quot; before long meetings). Programming is hard work. If you want a guru, go climb a mountain (results not guaranteed). 
&lt;/p&gt;

&lt;h3&gt;More Yellow Flags&lt;/h3&gt;
&lt;p&gt;
I sometimes get job descriptions and do interviews that can put me off. &quot;JavaScript Ninja&quot; is one flag.
&lt;/p&gt;

&lt;p&gt;
&quot;We want someone who can &lt;em&gt;Hit the Ground Running and Work Independently&lt;/em&gt;,&quot; is another more subtle flag.
&lt;/p&gt;

&lt;p&gt;
  This usually means they want someone to work alone, not with the team.
&lt;/p&gt;

&lt;h3&gt;They Don&#39;t Want what&#39;s Good for Them&lt;/h3&gt;
&lt;p&gt;
Projects where the team doesn&#39;t want to deal with the &quot;details&quot; (actual problem-solving &quot;work&quot;), can sometimes lead to hiring a contractor to &quot;just get it done.&quot; (offload tasks) This can be harmful.
&lt;/p&gt;

&lt;p&gt;
If carried out, this can lead to the team not understanding the code as well. It can also make it very difficult for the contractor to get his job done.
&lt;/p&gt;

&lt;p&gt;
&quot;Hiring a guru&quot; can be like deciding to use a library (&lt;a href=&quot;http://www.prototypejs.org/&quot;&gt;Prototype JS&lt;/a&gt;, &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;, et c) as a &lt;a href=&quot;http://en.wikipedia.org/wiki/Golden_hammer&quot;&gt;Golden Hammer&lt;/a&gt;.  There are no magic solutions.
&lt;/p&gt;

&lt;p&gt;
Not surprisingly, the desire for a &quot;JavaScript Ninja&quot; often goes hand-in-hand with a request for one of these libraries. 
&lt;/p&gt;

&lt;h3&gt;Teamwork and Ownership&lt;/h3&gt;

&lt;p&gt;
The reality is that the more successful projects have better cooperation and communication.
Hiring a &quot;guru&quot; or &quot;wizard&quot; contractor is usually carried out for the
worst reasons (&quot;we&#39;re behind&quot;), and with the worst process (&quot;let&#39;s
have the contractor own this part&quot;). Hiring new people takes time. Even a contractor. It
also takes time integrating the new person, explaining the problem space, tried solutions, project status, and workflow. So hiring a contractor to &quot;catch up&quot; isn&#39;t generally a good idea.
&lt;/p&gt;

&lt;p&gt;
Having code in the project that is owned by the contractor gets the 
company in technical debt. It accomplishes this by leaving the company with code that they do not understand. 
&lt;/p&gt;

&lt;p&gt;
Having the contractor sit and work apart from the team often makes it much harder for the contractor to do a proper job. 
&lt;/p&gt;

&lt;h3&gt;Change&lt;/h3&gt;
&lt;p&gt;
When [x_new_feature] is introduced, it might require change to the existing code. If it&#39;s a new feature, then it often means that the requirements changed in some way. Often the existing code is not designed to accommodate the new change (normal). If the contractor is asked to build [x_new_feature], and he is working alone, well, then he either has to step outside his role and change existing code (can get him fired) or the new feature will get built in a hackish way around the other non-changing code that is owned by the team. 
&lt;/p&gt;

&lt;p&gt;
It is beneficial for the company
employees to understand as much of the company code as possible. A
contractor should be working with the
team, trying to understand their problem with them, collaboratively, and helping
them to find solutions to the problems.
&lt;/p&gt;

&lt;h3&gt;Hire a Ninja?&lt;/h3&gt;
&lt;p&gt;
I am very cautious of anyone who presents himself as a &quot;ninja&quot; or a &quot;guru&quot;. Posting an ad for &quot;JavaScript Guru Wanted,&quot; is asking for someone who is both overconfident and underqualified, and that is disastrous combination of characteristics in a potential newhire. 
&lt;/p&gt;

&lt;p&gt;
Pair programming, metaphor/ubiquitous language, daily standups should include the contractor. With complicated applications, TDD and Pair can be practiced in a way that can significantly benefit the successful outcome of the project and collective understanding of the code. Even with a contractor. 

&lt;/p&gt;

&lt;p&gt;
 Let the contractor know how your team works and how he&#39;s expected to fit in. This will help avoid misunderstandings and can help your team find the right contractor for the job. 
&lt;/p&gt;
</description>
	    <dc:date>2008-05-06T20:15:04-05:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/05/05/APE-JavaScript-Library">
	    <title>APE JavaScript Library</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/05/05/APE-JavaScript-Library</link>
        <description>&lt;p&gt;Frustrated with every other JavaScript framework, I have decided to write something better.
&lt;/p&gt;

&lt;h3&gt;Points&lt;/h3&gt;
&lt;ul&gt;
 &lt;li&gt; Minimal Framework, mainly used for AOP and OOP functionality &lt;/li&gt;
 &lt;li&gt; All code is tested using YUI Test (TDD) &lt;/li&gt;
 &lt;li&gt; AOP Event System with asynchronous error handling &lt;/li&gt;
 &lt;li&gt; Namespacing &lt;/li&gt;
 &lt;li&gt; Modularity, Cohesion, Packaging &lt;/li&gt;
 &lt;li&gt; No browser detection &lt;/li&gt;
 &lt;li&gt; JSDoc &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here it is: &lt;a href=&quot;/ape/&quot;&gt;APE JavaScript Library&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Testing&lt;/h3&gt;
&lt;p&gt;
By using a test driven approach, I was able to avoid problems that I found in other libraries. 
&lt;/p&gt;

&lt;h4&gt;APE Core&lt;/h4&gt;
&lt;p&gt;
  The core of APE is so small that the overhead of adding APE to a project is significantly less than that of other libraries. 
&lt;/p&gt;

&lt;p&gt;
 I generally don&#39;t like a lot of the libraries that use a &lt;a href=&quot;http://en.wikipedia.org/wiki/God_object&quot;&gt;&quot;GOD&quot; object&lt;/a&gt; approach. These objects can be recognized by being undefinable by more than a few words. The approach is quite popular and annoys me to no end. How do you describe the &lt;code&gt;dojo&lt;/code&gt; object, for example?
&lt;/p&gt;

&lt;p&gt;
 The &lt;code&gt;APE&lt;/code&gt; object itself is defined in APE.js, providing only the most basic things that a framework would need: 1) Object creational features, and 2) a core namespace. Although some might argue that a library core needs more than that. 
&lt;/p&gt;

&lt;p&gt;
The APE object is only &lt;a href=&quot;/ape/build/APE.js&quot;&gt;&lt;abbr title=&quot;Three Kilobytes&quot;&gt;3k&lt;/abbr&gt; minified&lt;/a&gt; and less than &lt;abbr title=&quot;One Kilobyte&quot;&gt;1k&lt;/abbr&gt; gzipped. The size is not the point. The point is that APE is not a kitchen-sink, or God object.
&lt;/p&gt;


&lt;h3&gt;Help Wanted&lt;/h3&gt;
&lt;p&gt;
 You can join, too! Here&#39;s what APE needs:
&lt;/p&gt;

&lt;h4&gt;New Features&lt;/h4&gt;
&lt;p&gt;
 There is much more that can be added. For example, some ADT&#39;s: Resizable (croppers, windows), FormSerializer.
&lt;/p&gt;
&lt;h4&gt;SVN and Bugzilla&lt;/h4&gt;
&lt;p&gt;
 I still need to add hosted SVN to the directories and install bugzilla.
&lt;/p&gt;

&lt;h4&gt;Performance Tests&lt;/h4&gt;
&lt;p&gt;
  I&#39;ve always been big on performance, and not just for JavaScript but all areas of life, and I am very competitive in nature. 
&lt;/p&gt;

&lt;p&gt;
APE needs benchmarks to compare with other libraries. This will provide useful analysis for other library authors who aspire to have code that is as performant as that in APE.
&lt;/p&gt;

&lt;p&gt;
 Anyone interested in joining this project contact dhtmlkitchen - at - gmail - dot - com. 
&lt;/p&gt;
</description>
	    <dc:date>2008-05-05T19:26:12-05:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/04/19/Testing-JavaScript">
	    <title>Testing JavaScript</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/04/19/Testing-JavaScript</link>
        <description>&lt;p&gt;Slides from JS Meetup&#39;s &quot;Testing JavaScript&quot;
&lt;/p&gt;
&lt;div style=&quot;width:425px;text-align:left;margin:auto&quot; id=&quot;__ss_361183&quot;&gt;&lt;object style=&quot;margin:0px&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://static.slideshare.net/swf/ssplayer2.swf?doc=testing-1208582883379454-8&quot;/&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot;/&gt;&lt;embed src=&quot;http://static.slideshare.net/swf/ssplayer2.swf?doc=testing-1208582883379454-8&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;425&quot; height=&quot;355&quot;&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style=&quot;font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;&quot;&gt;&lt;a href=&quot;http://www.slideshare.net/?src=embed&quot;&gt;&lt;img src=&quot;http://static.slideshare.net/swf/logo_embd.png&quot; style=&quot;border:0px none;margin-bottom:-5px&quot; alt=&quot;SlideShare&quot;/&gt;&lt;/a&gt; | &lt;a href=&quot;http://www.slideshare.net/dhtml/testing-361183?src=embed&quot; title=&quot;View &#39;Testing&#39; on SlideShare&quot;&gt;View&lt;/a&gt; | &lt;a href=&quot;http://www.slideshare.net/upload?src=embed&quot;&gt;Upload your own&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
</description>
	    <dc:date>2008-04-19T01:03:24-05:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/02/21/Load-Time-Constants-Part-I">
	    <title>Load Time Constants, Part I</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/02/21/Load-Time-Constants-Part-I</link>
        <description>&lt;p&gt;
One issue that comes up when writing scripts is addressing upper and lower case tag names. 
&lt;/p&gt;
&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;
An XHTML document served with the content type &lt;code&gt;application/xhtml+xml&lt;/code&gt; will have all lower case tag names in the &lt;abbr title=&quot;Document Object Model&quot;&gt;DOM&lt;/abbr&gt;.
The exact same page served with the content type &lt;code&gt;text/html&lt;/code&gt; will have all upper case tag names.
&lt;/p&gt;

&lt;p&gt;
This can affect the way we script our pages by requiring us to clutter up the script with calls to &lt;code&gt;toLowerCase()&lt;/code&gt;.
&lt;/p&gt;

&lt;h3&gt;
Example
&lt;/h3&gt;
&lt;pre&gt;
function getCoords(el) {
  for( var parent = el.parentNode; parent &amp;amp;&amp;amp; parent !== container; 
                                         parent = parent.parentNode) { 
    if( parent.tagName&lt;strong style=&quot;color:red&quot;&gt;.toLowerCase()&lt;/strong&gt; == &quot;table&quot; ) {
      var pcs = getComputedStyle(parent, &quot;&quot;);
    }
  }
}
&lt;/pre&gt;
&lt;p&gt;
It&#39;s easy enough to call &lt;code&gt;el.tagName.toLowerCase()&lt;/code&gt; but when this is done repeatedly in a loop, it can slow things down. 
&lt;/p&gt;

&lt;h3&gt;Solution&lt;/h3&gt;
&lt;p&gt;
One way to avoid that issue is to define a run time constant. This would be done in a closure over the function that was calling &lt;code&gt;toLowerCase()&lt;/code&gt;
&lt;/p&gt;
&lt;pre&gt;
(function(){ 

var TABLE = /^h/.test(document.documentElement.tagName) ? &quot;table&quot; : &quot;TABLE&quot;;

function getCoords(el) {
  for( var parent = el.parentNode; parent &amp;amp;&amp;amp; parent !== container; 
                                         parent = parent.parentNode) { 
    if( &lt;strong style=&quot;color: #060&quot;&gt;parent.tagName == TABLE&lt;/strong&gt; ) {
      var pcs = getComputedStyle(parent, &quot;&quot;);
    }
  }
}
})();
&lt;/pre&gt;
&lt;h3&gt;Scope&lt;/h3&gt;
&lt;p&gt;
  Function &lt;code&gt;getCoords()&lt;/code&gt; can see &lt;code&gt;TABLE&lt;/code&gt;, but nothing outside of that closure can see &lt;code&gt;getCoords&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Function &lt;code&gt;getCoords&lt;/code&gt; must then be exported by assigning it to a property of a globally accessible object (using the Module Pattern or Exporting Pattern).
&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;
Having a constant can help to speed up the loop by avoiding the property lookup and 
an extra function call to &lt;code&gt;toLowerCase()&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Having one constant value reduces the number of strings being created and garbage collected. Since 
an active garbage collector can also hurt performance, a constant value avoids this hit.
&lt;/p&gt;

&lt;p&gt;
Finally, the result can be compressed using a compression tool, resulting in &lt;code&gt;TABLE&lt;/code&gt; being converted in to a one letter symbol.
&lt;/p&gt;
</description>
	    <dc:date>2008-02-21T17:20:24-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/02/01/Google-Code-in-Safari">
	    <title>Google Code in Safari</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/02/01/Google-Code-in-Safari</link>
        <description>&lt;p&gt;
 The JavaScript Gurus at google have developed a neat feature for Googlecode. It verifies the form for you, to make sure you&#39;re data is OK. If their script thinks you&#39;ve correctly filled out the form, the submit button gets enabled.
&lt;/p&gt;

&lt;p&gt;
 This has got to be one of the dumbest things I&#39;ve seen in a long time...
&lt;/p&gt;

&lt;img src=&quot;/img/blog/googlecode.jpg&quot; alt=&quot;Google Code: Borken in WebKit&quot;/&gt;

&lt;p&gt;
 See that &lt;samp&gt;Create Project&lt;/samp&gt; button up there?
&lt;/p&gt;

&lt;p&gt;
It&#39;s disabled, isn&#39;t it? Yes, it is. And if you&#39;re using Webkit, it will stay disabled. 
&lt;/p&gt;

&lt;h3&gt;User Experience and Usability&lt;/h3&gt;
&lt;p&gt;
 There is JavaScript code in Google&#39;s &quot;create project&quot; page that enables the button. Since it doesn&#39;t work in Webkit, the website is unusable.
&lt;/p&gt;

&lt;h3&gt;Surprised?&lt;/h3&gt;
&lt;p&gt;
 It&#39;s nothing to be surprised about. The new GMail is just as buggy in Safari as the old one was; sometimes the message gets only half-sent (truncation). Google Groups does the same thing; sends half a message sometimes (embarrassingly horrible code there). Groups&#39; &quot;search this group&quot; feature doesn&#39;t work in any browser if you have language pref (&lt;a href=&quot;http://groups.google.com/group/comp.lang.javascript/topics&quot;&gt;link&lt;/a&gt;). Groups also has the same problem with the button becoming disabled when it is clicked, which doesn&#39;t work so well on a wifi remote connection if you got disconnectet. It really is a piece of garbage. 
&lt;/p&gt;

&lt;h3&gt;A Reputation to Live up to&lt;/h3&gt;
&lt;p&gt;
Arrogantly bolstered by aggressive financial growth, the Google Empire churns out one poorly engineered software project after another. Each project gaining massive recognition, as it bears the Google brand name. Like Microsoft, they&#39;re accepted as de facto in the industry; (1) Like Microsoft, they aggressively hire engineers, acquire competitors, et c. (2)
&lt;/p&gt;

&lt;p&gt;
(1) Got an iPhone? I bet it came with Google&#39;s lame mobile search instead of the better Yahoo Mobile search.
&lt;/p&gt;

&lt;p&gt;
(2)
Google docs and spreadsheets, an acquisition, is developed and maintained by recent grads and contractors. No surprise that even after nearly 4 years it&#39;s still almost completely unusable. 
&lt;/p&gt;

&lt;h3&gt;Source Code&lt;/h3&gt;
&lt;p&gt;
The inline &amp;lt;script&amp;gt; tag for &lt;a href=&quot;http://code.google.com/hosting/createProject.do&quot;&gt;Google Code&lt;/a&gt; contains the relevant button-enabling code. No type attribute on the script tag, missing &lt;code&gt;var&lt;/code&gt; keyword for most of the variables (which are all top level). The obvious point is the accessibility issue: Users who don&#39;t have a browser Google supports are blocked.
&lt;/p&gt;

&lt;pre&gt;
&amp;lt;script&amp;gt;
 _exposeExistingLabelFields(&#39;edit&#39;);
 var submit = document.getElementById(&#39;submit&#39;);
 submit.disabled=&#39;disabled&#39;;
 var projectname = document.getElementById(&#39;projectname&#39;);
 var licensekey = document.getElementById(&#39;license_key&#39;);
 var summary = document.getElementById(&#39;summary&#39;);
 var description = document.getElementById(&#39;description&#39;);
 var cg = document.getElementById(&#39;cg&#39;);
 projectname.focus();
 var solelyDigits = /^[-0-9]+$/
 var hasUppercase = /[A-Z]/
 var projectRE = /^[a-z0-9][-a-z0-9]*$/
 function checkprojectname() {
 &lt;b style=&quot;color:#c00&quot;&gt;name = projectname.value;&lt;/b&gt;
 &lt;b style=&quot;color:#c00&quot;&gt;feedback = document.getElementById(&#39;projectnamefeedback&#39;);&lt;/b&gt;
 &lt;b style=&quot;color:#c00&quot;&gt;submit.disabled=&#39;disabled&#39;;&lt;/b&gt;
 feedback.style.color = &#39;red&#39;;
 if (name == &#39;&#39;) {
 feedback.innerHTML = &#39;&#39;;
 } else if (hasUppercase.test(name)) {
 feedback.innerHTML = &#39;Must be all lowercase&#39;;
 } else if (solelyDigits.test(name)) {
 feedback.innerHTML = &#39;Must include a lowercase letter&#39;;
 } else if (!projectRE.test(name)) {
 feedback.innerHTML = &#39;Invalid project name&#39;;
 } else if (name.length &amp;gt; 50) {
 feedback.innerHTML = &#39;Project name is too long&#39;;
 } else {
 feedback.innerHTML = &#39;&#39;;
 feedback.style.color = &#39;&#39;;
 
 checksubmit()
 }
 }
 function checksubmit() {
 submit.disabled=&#39;disabled&#39;;
 if (projectname.value.length &amp;gt; 0 &amp;amp;&amp;amp;
 licensekey.value.length &amp;gt; 1 &amp;amp;&amp;amp; 
 summary.value.length &amp;gt; 3 &amp;amp;&amp;amp; 
 description.value.length &amp;gt; 3 &amp;amp;&amp;amp; 
 (cg == undefined || cg.value.length &amp;gt; 1)) {
 submit.disabled=&#39;&#39;;
 }
 }
 checkprojectname();
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;h4&gt;Looking at the Mess&lt;/h4&gt;
&lt;p&gt;
Notice the:
&lt;code&gt;submit.disabled=&#39;disabled&#39;;&lt;/code&gt;, well that&#39;s pretty odd. I can guess what the author was trying to do. The browser might do a boolean conversion on the &#39;disabled&#39;, to get a value of &lt;code&gt;true&lt;/code&gt;, but that is not guaranteed. I&#39;m guessing there&#39;s code somewhere else that says &lt;code&gt;submit.disabled = &quot;&quot;&lt;/code&gt; or &lt;code&gt;submit.removeAttibute(&quot;disabled&quot;)&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
 I love how they embed all the localized error messages in a series &lt;code&gt;if else&lt;/code&gt; of &lt;code&gt;checkprojectname&lt;/code&gt; function. A fine example of Google&#39;s standard of quality.
&lt;/p&gt;

&lt;h3&gt;What I Think of Google&#39;s Code&lt;/h3&gt;
&lt;p&gt;
 Garbage. I wouldn&#39;t care so much if their god damned page worked.
&lt;/p&gt;
</description>
	    <dc:date>2008-02-01T02:17:05-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/01/31/Crashed">
	    <title>Crashed!</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/01/31/Crashed</link>
        <description>&lt;p&gt;
DHTML Kitchen was down.
&lt;/p&gt;


&lt;p&gt;
My web host upgraded CPanel. They did not tell me, but they did. In so
doing, the permissions on my database got changed, so my blog software could not access my MySQL database. The blog software threw an error, which crashed 
Tomcat. Tomcat could not be restarted, because when the app loaded, the blog software would try to read from the database, which would cause another crash, bringing Tomcat right down again.
&lt;/p&gt;

&lt;p&gt;
Glad it&#39;s back up and running now.
&lt;/p&gt;
</description>
	    <dc:date>2008-01-31T02:25:05-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2008/01/04/Event-Notification-System">
	    <title>Event Notification System</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2008/01/04/Event-Notification-System</link>
        <description>            &lt;p&gt;
    An &lt;dfn&gt;Event Notification System&lt;/dfn&gt; is an object that manages notification of events to multiple callbacks. 
    The &lt;dfn&gt;Event Notification System&lt;/dfn&gt; uses an &lt;dfn&gt;Event Registry&lt;/dfn&gt; to store the callbacks as bound methods. When the event 
    fires, the callbacks are invoked.

&lt;/p&gt;

&lt;h3&gt;Event Registry&lt;/h3&gt;
&lt;p&gt;
    An &lt;dfn&gt;Event Registry&lt;/dfn&gt; is a store of bound methods. 
    An &lt;dfn&gt;Event Registry&lt;/dfn&gt; is used by an &lt;dfn&gt;Event Notification System&lt;/dfn&gt;. 
    The &lt;dfn&gt;Event Notification System&lt;/dfn&gt; is tightly coupled with the &lt;dfn&gt;Event Registry&lt;/dfn&gt;. Sometimes it is referred to &lt;em&gt;as&lt;/em&gt; the &lt;dfn&gt;Registry&lt;/dfn&gt;.
    In reality, the &lt;dfn&gt;Registry&lt;/dfn&gt; is just a data structure and the &lt;dfn&gt;Event Notification System&lt;/dfn&gt; is a behavioral object.

&lt;/p&gt;

&lt;p&gt;Almost Every JavaScript library has an &lt;dfn&gt;Event Registry&lt;/dfn&gt;, or at least some way of dealing with event notification. 
&lt;/p&gt;

&lt;h4&gt;For example:&lt;/h4&gt;
&lt;pre&gt;// YUI:
YAHOO.util.Event.addListener( link, &quot;click&quot;, linkClickHandler, thisArg );

// Prototype: &lt;span style=&quot;color: rgb(153, 0, 0);&quot;&gt;(not a registry, but the old &#39;addEvent&#39; function renamed)&lt;/span&gt;.
Event.observe( link, &quot;click&quot;, linkClickHandler ); 

// Dojo:
dojo.connect( link, &quot;onclick&quot;, window, &quot;linkClickHandler&quot; );
&lt;/pre&gt;

&lt;p&gt;
    They&#39;re all different in how they work. 

&lt;/p&gt;

&lt;p&gt;
    The &lt;dfn&gt;Event Registry&lt;/dfn&gt; is useful for a few reasons. 
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;It allows multiple callbacks to be assigned to a function call.&lt;/li&gt;
    &lt;li&gt;Provides a usable alternative to &lt;code&gt;attachEvent&lt;/code&gt;. Internet Explorer 7 and below has &lt;code&gt;attachEvent&lt;/code&gt;/&lt;code&gt;detachEvent&lt;/code&gt;. The callback function for &lt;code&gt;attachEvent&lt;/code&gt; executes in global 
    context (&lt;code&gt;this&lt;/code&gt; is &lt;code&gt;window&lt;/code&gt;), not the object it was attached to.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;
    A good &lt;dfn&gt;Event Registry&lt;/dfn&gt; solves these problems. A good &lt;dfn&gt;Event Registry&lt;/dfn&gt; also allows for context resolution with an optional 
    &lt;code&gt;thisArg&lt;/code&gt;. A good &lt;dfn&gt;Event Registry&lt;/dfn&gt; also allows custom events to be registered using the same interface.
&lt;/p&gt;

&lt;p&gt;
    A poorly designed &lt;dfn&gt;Event Registry&lt;/dfn&gt; concerns itself with things related to native events (&lt;code&gt;DOMContentLoaded&lt;/code&gt;, &lt;code&gt;keyPress&lt;/code&gt;, et c). A poorly designed 
    Event Registry does not pass an event object to the callback (perhaps trying to use &lt;code&gt;eval&lt;/code&gt; to pass varargs). 
&lt;/p&gt;

&lt;h3&gt;Error Handling in an &lt;dfn&gt;Event Notification System&lt;/dfn&gt;&lt;/h3&gt;

&lt;h4&gt;Callback Errors Should not Break the Registry&lt;/h4&gt;
&lt;p&gt;A good &lt;dfn&gt;Event Registry&lt;/dfn&gt; does not allow any callback to break the registry.
&lt;/p&gt;

&lt;p&gt;
    One common problem in most &lt;dfn&gt;Event Notification System&lt;/dfn&gt;s (such as Dojo, Mochikit, YUI, and jQuery) is that they allow the callback to break the System. If a callback fails, it prevents subsequent callbacks from firing. A callback should not be given the ability to break the &lt;dfn&gt;Registry&lt;/dfn&gt;. 
&lt;/p&gt;

&lt;p&gt;
    Here&#39;s how to break a &lt;dfn&gt;Registry&lt;/dfn&gt; that doesn&#39;t consider errors:
&lt;/p&gt;
&lt;pre&gt;var passed = false;
addCallback( link, &quot;click&quot;, function(){ setTimeout(checkTitle, 500); } );
addCallback( link, &quot;click&quot;, function(){ throw Error(&#39;bad&#39;); } );
addCallback( link, &quot;click&quot;, function(){ passed = true; } );

function checkTitle(){ 
    if(!passed) 
        alert(&quot;registry broken: second callback did not fire.&quot;);
    else 
        alert(&#39;passed&#39;);
}
&lt;/pre&gt;

&lt;p&gt;
    Callbacks sometimes throw Errors. It is important for the &lt;dfn&gt;Event Registry&lt;/dfn&gt; to consider this and take the responsibility to handle these errors properly. If an error occurs in a callback, it should not break the &lt;dfn&gt;Registry&lt;/dfn&gt;. 

&lt;/p&gt;

&lt;p&gt;
    It should be guaranteed that all callbacks fire, even when earlier callbacks throw errors. This is a natural 
    expectation; it&#39;s exactly how DOM Events work:
&lt;/p&gt;

&lt;h4&gt;DOM Events Test&lt;/h4&gt;
&lt;div&gt;
&lt;pre id=&quot;registry-dom-event-test&quot;&gt;(function(){
var s = document.getElementById(&#39;r-test&#39;);

var el = document.getElementById(&quot;registry-dom-event-button&quot;);
if(!window.hasDocumentListeners) {
    el.addEventListener( &quot;click&quot;, setUpCheck, false );
    el.addEventListener(&quot;click&quot;, throwError, false );
    // setTitle must fire.
    el.addEventListener( &quot;click&quot;, setTitle, false ); 

    window.hasDocumentListeners = true;
}
function setUpCheck(){ setTimeout(checkTitle, 500); }
function throwError(){ document.title = &quot;&quot;; throw Error(&#39;bad&#39;); }
function setTitle(){ document.title += &#39;ok&#39;; }
function checkTitle(ev) {
    if(document.title != &quot;ok&quot;) {
        alert(&quot;DOM Events broken: setTitle did not fire. &quot; + document.title );
    }
    else {
        alert(&quot;passed&quot;);
    }
}
})();&lt;/pre&gt;
&lt;button id=&quot;registry-dom-event-button&quot; onfocus=&quot;eval(document.getElementById(&#39;registry-dom-event-test&#39;).textContent)&quot;&gt;eval&lt;/button&gt;
&lt;/div&gt;
&lt;h4&gt;Result and Analysis&lt;/h4&gt;

&lt;p&gt;There should be 1 error and an alert &lt;kbd&gt;passed&lt;/kbd&gt;. This indicates that after the error happened, the &lt;code&gt;setTitle&lt;/code&gt; callback successfully fired.
&lt;/p&gt;

&lt;p&gt;
    This example assumes:
&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; Callbacks fire in the order in which they were registered. &lt;/li&gt;

    &lt;li&gt; The &lt;kbd&gt;bad&lt;/kbd&gt; error in the first callback does not stop subsequent callbacks from firing. &lt;/li&gt;
    &lt;li&gt; The button supports the &lt;a href=&quot;http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Registration-interfaces&quot;&gt;&lt;code&gt;EventTarget&lt;/code&gt; interface&lt;/a&gt; (not in IE7).
&lt;/li&gt;
&lt;li&gt; The &lt;code&gt;button&lt;/code&gt; supports onfocus (not in safari &lt;a href=&quot;http://bugs.webkit.org/show_bug.cgi?id=16331&quot;&gt;bug 16331&lt;/a&gt;).

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Proper Callback Error-Handling&lt;/h3&gt;
&lt;p&gt;
    Throwing the error in a separate thread allows the callstack to continue without breaking. Any errors that are thrown 
    are thrown in the correct order in the callstack. The &lt;code&gt;Event Publisher&lt;/code&gt;&#39;s &lt;code&gt;fire&lt;/code&gt; 
    function would have something like this:
&lt;/p&gt;

&lt;pre&gt;try {
// If an error occurs, continue the event fire,
// but still throw the error.
  callback.call( thisArg, ev );
}
catch( ex ) {
  setTimeout(&quot;throw ex;&quot;, 1); 
}
&lt;/pre&gt;

&lt;p&gt;
  The one subtle issue is that &lt;code&gt;setTimeout&lt;/code&gt; uses global scope, like the Function constructor, not like eval, which runs in the calling context&#39;s scope. 
&lt;/p&gt;

&lt;p&gt;
  A closure must be used to preserve the &lt;code&gt;ex&lt;/code&gt; variable.
&lt;/p&gt;

&lt;pre&gt;try {
// If an error occurs, continue the event fire,
// but still throw the error.
  callback.call( thisArg, ev );
}
catch( ex ) {
  setTimeout(function(){ throw ex; }, 1); 
}
&lt;/pre&gt;


&lt;h3&gt;Event Registry Test&lt;/h3&gt;
&lt;p&gt;
  The remaining problem with the above code is that the error condition is untestable. Writing a test suite forced me to realize this 
  and I changed the design.
&lt;/p&gt;

&lt;pre&gt;try {
if(csi[0].call(csi[1], e) == false)
  preventDefault = true; // continue main callstack and return false afterwards.
}
catch(ex) {
  APE.deferError(ex);
}
&lt;/pre&gt;

&lt;p&gt;
  Where &lt;code&gt;APE.deferError&lt;/code&gt; is defined:

&lt;/p&gt;

&lt;pre&gt;deferError : function(error) {		
  setTimeout(function deferError(){throw error;},1);
}
&lt;/pre&gt;

&lt;p&gt;
    I have included the source code for my own &lt;dfn&gt;Event Registry&lt;/dfn&gt;, along with this 
    &lt;a href=&quot;/ape/test/tests/EventPublisher-test.html&quot; onclick=&quot;window.open(this.href);return false;&quot;&gt;test&lt;/a&gt;,
    which shows how I managed to test &lt;code&gt;APE.deferError&lt;/code&gt;.
&lt;/p&gt;

&lt;h3&gt;Performance?&lt;/h3&gt;

&lt;p&gt;
    Wrapping each callback call in a &lt;code&gt;try catch&lt;/code&gt; might seem to be bad for performance. 
    I tried it with mousemove event on my drag code, dragging multiple drag objects at a time 
    (&lt;a href=&quot;/ape/example/drag/droptarget/&quot;&gt;example&lt;/a&gt;), and it seemed fast enough; I did not notice performance 
    problems in any browser. There is most likely some performance overhead using this approach,
    but I did not find a need to write a benchmark. 
&lt;/p&gt;

&lt;div class=&quot;gotcha&quot;&gt;
    &lt;p&gt;
        &lt;code&gt;src&lt;/code&gt; should never be a string. Although this may seem obvious, YUI actually allows &lt;code&gt;src&lt;/code&gt; to be a string, 
        where the string represents an element&#39;s ID. The document is polled regulary until 
        the element with the &lt;code&gt;id&lt;/code&gt; matching string is found and then the callback is attached to that element. If the element has been renamed, the document is still polled and silent failure occurs.
    &lt;/p&gt;

    &lt;p&gt;
        This can lead to silent failure or corrupted application state if the element is not found. It is not recommended. 
    &lt;/p&gt;
&lt;/div&gt;

&lt;h3&gt;Packaging and API Design&lt;/h3&gt;
&lt;p&gt;
    The &lt;dfn&gt;Event Notification System&lt;/dfn&gt; is a low level component with no external dependencies.
&lt;/p&gt;

&lt;p&gt;
    Being a low level component, the &lt;dfn&gt;Event Notification System&lt;/dfn&gt; should be maximally stable (no efferent couplings), and maximally abstract. In this case, the Event Notification system is maximally abstract because 
    it can&#39;t be subclassed or used independently. 
&lt;/p&gt;

&lt;h3&gt;Stable Dependencies Principle&lt;/h3&gt;
&lt;p&gt;Depend in the direction of stability&lt;/p&gt;

&lt;h3&gt;Stable Abstractions Principle&lt;/h3&gt;
&lt;p&gt;

    A package should be as abstract as it is stable.
&lt;/p&gt;

&lt;h3&gt;Reuse Equivalence Principle&lt;/h3&gt;
&lt;p&gt;
    The Granule of Reuse is the Granule of Release.
&lt;/p&gt;

&lt;p&gt;
    The &lt;dfn&gt;Event Notification System&lt;/dfn&gt; is a low level component with no external dependencies. It is intentionally 
    packaged as a single, tested unit. It amplifies the essential (event notification) and eliminates the irrelevant.

&lt;/p&gt;

&lt;p&gt;
    Creating special cases for handling &lt;acronym title=&quot;Document Object Model&quot;&gt;DOM&lt;/acronym&gt; events (&lt;code&gt;keyCode&lt;/code&gt;, et c),
    would reduce abstraction. These special cases are perfectly valid, but do not belong
    in the &lt;dfn&gt;Registry&lt;/dfn&gt;. Special case needs can either be hard-coded into end-implementation code 
    (using feature/capability detection) or, if the special-case logic is complex, programmed into an object that performs a task (such as an Adapter object). 
&lt;/p&gt;

&lt;p&gt;
    An example of an Adapter object would be 
    a &lt;a href=&quot;/learn/js/load/&quot;&gt;Content Load Adapter&lt;/a&gt; or a KeyEvent Adapter (key events are highly inconsistent across platforms).
    Such objects would be slightly higher-level and, having at least one dependency, would be less stable (though this is not a bad thing).

&lt;/p&gt;

&lt;h3&gt;Department Store JavaScript&lt;/h3&gt;
&lt;p&gt;
    [insert_popular_library_name_here] usually include more code than any one application could possibly use in an attempt to 
    cover the needs of every application. 
&lt;/p&gt;

&lt;p&gt;
    Libraries that add more functionality into one module than is usually needed, or create modules 
    that are not cohesive do so in spite of commonly known software package design concepts. The one-stop library approach is appealing because it allows developers to &quot;stop cobbling bits of javascript.&quot; 
&lt;/p&gt;

&lt;h3&gt;Performance (Again)&lt;/h3&gt;
&lt;p&gt;

    Load Time Performance problems can be acheived by creating custom javascript builds on the server. Hand-rolled &quot;combination&quot; files or utils files are fine for web sites with fewer pages. Sites that don&#39;t require 200k+ of additional javascript should not include such functionality.
&lt;/p&gt;
</description>
	    <dc:date>2008-01-04T21:42:32-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2007/11/24/Browser-Detection">
	    <title>Browser Detection</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2007/11/24/Browser-Detection</link>
        <description>&lt;p&gt;
There have been &lt;a href=&quot;http://www.jibbering.com/faq/faq_notes/not_browser_detect.html&quot;&gt;many&lt;/a&gt;, 
&lt;a href=&quot;http://developer.mozilla.org/en/docs/Using_Web_Standards_in_your_Web_Pages#Developing_Cross_Browser.2FCross_Platform_Pages&quot;&gt;many&lt;/a&gt;, 
&lt;a href=&quot;http://www.quirksmode.org/js/support.html&quot;&gt;articles&lt;/a&gt; and 
&lt;a href=&quot;http://ejohn.org/blog/building-a-javascript-library/#comment-232407&quot;&gt;discussions&lt;/a&gt; that 
&lt;a href=&quot;http://ajaxian.com/archives/the-dangers-of-browser-detect&quot;&gt;eschew&lt;/a&gt;  
&lt;a href=&quot;http://dylanschiemann.com/2006/12/16/browser-detection-101-back-to-the-basics/&quot;&gt;browser&lt;/a&gt; &lt;a href=&quot;http://bclary.com/blog/2006/05/16/yahoo-and-the-evils-of-vendorversion-browser-detection/&quot;&gt;detection&lt;/a&gt;, yet it continues.
&lt;/p&gt;

&lt;p&gt;
	Despite all of this information, browser detection can be seen in most of the popular 
	JavaScript libraries including Prototype,
	YUI, Dojo, jQuery, and is present in applications such as the newly refactored GMail:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
	For a better Gmail experience, use a fully supported browser.   
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
	Browser detection is bad for many reasons:
&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;Browsers change. &lt;/li&gt;
	&lt;li&gt;The User Agent string does not represent the browser reliably. &lt;/li&gt;
	&lt;li&gt;Even if it did, the browser doesn&#39;t represent feature support (See #1). &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
Browser detection is unrelated to the problem it is trying
to solve.
&lt;/p&gt;

&lt;p&gt;
Browser detection makes code hard to maintain. It accomplishes this by 
requiring that the next version of [insert_browser_name] will also have to be tested 
and special-cased in the code.
&lt;/p&gt;

&lt;h3&gt;Alternative: Feature Detection&lt;/h3&gt;
&lt;p&gt;
For example, does the browser support &lt;code&gt;opacity&lt;/code&gt;? This can easily be determined:
&lt;/p&gt;

&lt;pre&gt;
if(&quot;opacity&quot;in el.style) { }
&lt;/pre&gt;

&lt;p&gt;
Support of &lt;code&gt;opacity&lt;/code&gt; has nothing to do with whether that
browser actually is an IE version, nor is the reverse true: IE does not imply 
support (or lack of support) for &lt;code&gt;opacity&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Detection for feature support does not suffer from maintenance 
problems when Internet Explorer decides to support &lt;code&gt;opacity&lt;/code&gt;. &lt;a href=&quot;http://dev.opera.com/articles/view/using-capability-detection/&quot;&gt;Capability detection&lt;/a&gt; takes feature detection one step further.
&lt;/p&gt;


&lt;p&gt;
Once the code has been properly designed and tested, it should not be a problem to maintain.
&lt;/p&gt;

&lt;p&gt;
I have learned this the hard way and have tried to remove browser detection from 
my drag code, though evidence of my mistake is still present. I had to refactor my drag code in specific cases where it checked for browsers identifying with an Opera User Agent string (removed checks to &lt;code&gt;ua.opera&lt;/code&gt;). My code still contains one conditional branch that needs to be refactored, As is, the script works in all of the modern browsers (this is subject to change).
&lt;/p&gt;

&lt;p&gt;
With browser detection, the &lt;a href=&quot;http://books.google.com/books?id=u13hVoYVZa8C&amp;amp;pg=PA29&amp;amp;lpg=PA29&amp;amp;dq=internal+quality+beck&amp;amp;source=web&amp;amp;ots=GI592TgTag&amp;amp;sig=NwxZNg0dSzxPkgZpn5GYtTcIe54&quot;
&gt;internal quality&lt;/a&gt; of the code suffers, even if the code works. This is because it introduces a dynamic aspect that must be maintained as the browsers change. &lt;a href=&quot;http://c2.com/cgi/wiki?ImplementationDoesTooMatter&quot;&gt;Implementation Matters&lt;/a&gt;.
&lt;/p&gt;

&lt;h3&gt;ToBoolean&lt;/h3&gt;

&lt;p&gt;
Be careful when testing for values of properties. Some values may evaluate to 
false in a boolean context.
&lt;/p&gt;

&lt;pre&gt;
&lt;strong&gt;// Error-prone, scrollTop may be 0, which would evaluate to false&lt;/strong&gt;
if (document.body.scrollTop) {
    // statements that work with scrollTop property
}
&lt;/pre&gt;

&lt;h3&gt;The new GMail&lt;/h3&gt;
&lt;p&gt;New code should definitely not rely on browser detection&lt;/p&gt; 
&lt;p&gt;
GMail, which was recently redesigned, still uses browser detection and also punishes users with the performance hit of a misused HTTP redirect (HTTP/1.x 302 Moved Temporarily), or, if GMail finds your browser&#39;s User Agent header unsuitable, it &lt;em&gt;two&lt;/em&gt; HTTP redirects. 
&lt;/p&gt;

&lt;p&gt;
In fact, when developing for mobile phones, I have found 
Chris Penderick&#39;s 
&lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/59&quot;&gt;UserAgent switcher&lt;/a&gt; useful. Unfortunately, this confuses GMail, messing up the 
rendering and even encoding of messages.
&lt;/p&gt;

&lt;p&gt;
GMail seems to be predominantly developed with a windows-centric mentality. 
This is evidenced by the lack of support for Command + S to save in 
Mac, and the Safari and Opera bugs witnessed in earlier versions of GMail.
&lt;/p&gt;

&lt;h3&gt;Google Groups&lt;/h3&gt;
&lt;p&gt;
	Google Groups also relies on faulty browser detection to block 
	&lt;a href=&quot;http://groups.google.com/groups/profile?myprofile&quot;&gt;certain features&lt;/a&gt;.
&lt;/p&gt;
&lt;p style=&quot;text-align:center&quot;&gt;
&lt;img src=&quot;/img/blog/browser-detection.jpg&quot; style=&quot;width: 620px;height:448px;margin-left:-10px;&quot;
alt=&quot;Google Groups Browser Error, in a Draggable, Floating DHTML Pane&quot; /&gt;
&lt;small&gt;Google Groups Browser Error, in a Draggable, Floating DHTML Pane&lt;/small&gt;
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
This feature is not supported in your browser. Download a copy of Firefox or Internet Explorer to upload your picture.
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
I find it ironic that my browser can be assumed to support the draggable, floating pane, and not suitable for uploading a picture. The floating pane is draggable from anywhere inside it, so it is impossible for a user who gets the error to select the error message text.
&lt;/p&gt;

&lt;h3&gt;Acknowledgements&lt;/h3&gt;
&lt;p&gt;
Google deserves proper recognition for providing a clear example of why browser detection is a bad practice.
&lt;/p&gt;

&lt;h3&gt;Contrasting Example&lt;/h3&gt;
&lt;p&gt;
For proof that an effective Ajax application can be developed &lt;em&gt;without&lt;/em&gt; browser detection, have a look at &lt;a 
href=&quot;http://www.google.com/reader/&quot;&gt;Google Reader&lt;/a&gt;. 
&lt;/p&gt;

&lt;p&gt;
Browser Detection is mostly a bad idea. 
&lt;/p&gt;

&lt;p&gt;
In the meantime, I&#39;m looking for a decent mail application that runs in the browser. Both Yahoo mail 
and GMail fall short of my expectations.
&lt;/p&gt;


</description>
	    <dc:date>2007-11-24T21:40:19-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2007/11/08/Opera-Bug-getComputedStyle-Returns-Margin-for-Unset-Top-Left-Values">
	    <title>Opera Bug: getComputedStyle Returns Margin for Unset Top/Left Values</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2007/11/08/Opera-Bug-getComputedStyle-Returns-Margin-for-Unset-Top-Left-Values</link>
        <description>&lt;p&gt;
In Opera 9.2 &lt;code&gt;getComputedStyle(el, &#39;&#39;).getPropertyValue&lt;/code&gt; returns the margin value for &lt;code&gt;top&lt;/code&gt;/&lt;code&gt;left&lt;/code&gt; values when the &lt;code&gt;top&lt;/code&gt;/&lt;code&gt;left&lt;/code&gt; values aren&#39;t set. In Safari the returned values are &lt;samp&gt;&#39;auto&#39;&lt;/samp&gt; in this case.

&lt;/p&gt;

&lt;h3&gt;Example&lt;/h3&gt;
&lt;p&gt;
&lt;a href=&quot;/test/bug/getComputedStyle.html&quot; onclick=&quot;window.open(this.href);return false;&quot;&gt;testcase showing bug in Opera and Safari&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Workaround&lt;/h3&gt;
&lt;p&gt;
    The way to avoid the problem is to explicitly add &lt;code&gt;top&lt;/code&gt; and &lt;code&gt;left&lt;/code&gt; values to the stylesheet:
&lt;/p&gt;

&lt;pre&gt;
#Test {
  top: 0;
  left: 0;
}&lt;/pre&gt;

&lt;p&gt;
Then &lt;code&gt;getComputedStyle&lt;/code&gt; will return correct values for &lt;code&gt;top&lt;/code&gt;/&lt;code&gt;left&lt;/code&gt; (&lt;samp&gt;0px&lt;/samp&gt;) in Opera 9 and Safari. 
&lt;/p&gt;

&lt;h3&gt;pixelXXX&lt;/h3&gt;
&lt;p&gt;
 A convenient alternative would be a &lt;code&gt;currentStyle.pixelLeft&lt;/code&gt;. Only Opera and IE support &lt;code&gt;currentStyle&lt;/code&gt; and only Opera supports &lt;code&gt;currentStyle.pixelLeft&lt;/code&gt;. (IE supports &lt;code&gt;style.pixelLeft&lt;/code&gt;; this only reads from the &lt;code&gt;style&lt;/code&gt; attribute)
&lt;/p&gt;

&lt;p&gt;
 Mozilla does not support &lt;code&gt;pixelXXX&lt;/code&gt; properties at all, though Opera, IE, and Safari 3 all do.
&lt;/p&gt;
</description>
	    <dc:date>2007-11-08T18:25:06-06:00</dc:date>
	        </item>
            <item rdf:about="http://www.dhtmlkitchen.com/news/default/2007/10/21/Iteration-Enumeration-Primitives-and-Objects">
	    <title>Iteration, Enumeration, Primitives, and Objects</title>
	    <link>http://www.dhtmlkitchen.com/news/default/2007/10/21/Iteration-Enumeration-Primitives-and-Objects</link>
        <description>&lt;script type=&quot;text/javascript&quot;&gt;
function assertEquals( baseId ) {
	var src = document.getElementById( baseId + &quot;-source&quot; );
	var actual = String(eval( src.textContent || src.innerText ));
	var expectedEl = document.getElementById( baseId + &quot;-expected&quot; );
	var expected = expectedEl.textContent || expectedEl.innerText;
	var resultEl = document.getElementById( baseId + &quot;-result&quot; );
	resultEl.innerHTML = &quot;&amp;nbsp;&quot;
	resultEl.firstChild.data = actual;
// Because IE does not properly preserve white space, Our test must check the text 
// w/ nbsp removed.
	var actualNoNbsp = actual.replace(/(?:\u00a0)|[\s\s]+/g,&quot;&quot;);
	var expectedNoNbsp = expected.replace(/(?:\u00a0)|[\s\s]+/g,&quot;&quot;);
    var actualTrimmed = String.trim( actualNoNbsp );
    var expectedTrimmed = String.trim( expectedNoNbsp );
	resultEl.className = (expectedNoNbsp == actualTrimmed ? &quot;correct&quot; : &quot;incorrect&quot;);
}

String.nl = &quot;clipboardData&quot; in window ? &quot;\r\n&quot; : &quot;\n&quot;;
String.trim = function( s ) {
    return s.replace(/^\s+|\s+$/g,&quot;&quot;);
}
&lt;/script&gt;

&lt;h1&gt;
    Iteration VS Enumeration
&lt;/h1&gt;
&lt;p&gt;
    When trying to understand a language, it is necessary to first understand the words.
&lt;/p&gt;

&lt;dl&gt;
    &lt;dt&gt;iteration&lt;/dt&gt;
        &lt;dd&gt;the &lt;code&gt;for&lt;/code&gt; statement (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-12.6.3&quot; 
	title=&quot;The for Statement&quot;&gt;&amp;#167;12.6.3&lt;/a&gt;)&lt;/dd&gt;
    &lt;dt&gt;enumeration&lt;/dt&gt;
        &lt;dd&gt;the &lt;code&gt;for in&lt;/code&gt; statement (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-12.6.4&quot; 
	title=&quot;The for in Statement&quot;&gt;&amp;#167;12.6.4&lt;/a&gt;)&lt;/dd&gt;
&lt;/dl&gt;

&lt;p&gt;
    While writing &lt;cite&gt;&lt;a href=&quot;/learn/js/enumeration/&quot;&gt;Enumeration and Object Oriented JavaScript&lt;/a&gt;&lt;/cite&gt;, I read and reasearched (I also grew a beard and lost about 20lbs in the process). I read blogs and libraries to see what other programmers were doing.  I came across a peculiar quote by Alex Russel (dojo fame).
&lt;/p&gt;

&lt;blockquote cite=&quot;http://alex.dojotoolkit.org/?p=620&quot;&gt;
&lt;p&gt;
&lt;q&gt;The contortions that Ajax toolkit vendors go through to 
keep iteration over JavaScript objects and primitives coherent is, 
quite simply, insane. Much of Dojo, in particular, is designed around this problem.&lt;/q&gt;
&lt;/p&gt;
&amp;mdash;Alex Russel
&lt;/blockquote&gt;

&lt;h3&gt;Iterate Over a Primitive?&lt;/h3&gt;

&lt;p&gt;
    That sounds &lt;em&gt;completely&lt;/em&gt; insane! I read through dojo.js (uncompressed), which was pretty heavily commented, but could find no such contortion.
&lt;/p&gt;

&lt;p&gt;
    I thought about this some more, and I&#39;m pretty sure it&#39;s not possible.
&lt;/p&gt;

&lt;p&gt;
	Attempting to &lt;em&gt;enumerate&lt;/em&gt; over a primitive value results in an Object 
	being created. That object (including its prototype chain) is then enumerated over.
&lt;/p&gt;

&lt;pre&gt;
Boolean.prototype.crap = &quot;useless&quot;;
for(var prop in true) { alert(true[prop]); }
if(!delete Boolean.prototype.crap) 
    alert(&quot;uh oh :(&quot;);
&lt;/pre
&gt;&lt;button onclick=&quot;eval(this.previousSibling.innerHTML);&quot;&gt;eval&lt;/button&gt;


&lt;p&gt;Attempting to enumerate over a primitive will result 
in the evaluation of the primitive in creation of an object
(&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-9.9&quot; 
	title=&quot;The for in Statement&quot;&gt;&amp;#167;9.9&lt;/a&gt;), just as is with the property access operators, 
e.g. &lt;code&gt;true[ prop ]&lt;/code&gt; or &lt;code&gt;true.valueOf() === true&lt;/code&gt; or &lt;code&gt;1.1255.toPrecision(4);&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
    The internal &lt;code&gt;ToObject&lt;/code&gt; method, in the above case, will return a &lt;code&gt;Boolean&lt;/code&gt; object holding the value &lt;code&gt;true&lt;/code&gt;. The property named &lt;var&gt;crap&lt;/var&gt; is resolved in &lt;code&gt;Boolean.prototype&lt;/code&gt;, holding the string value &lt;code&gt;&quot;useless&quot;&lt;/code&gt;.
&lt;/p&gt;

&lt;h3&gt;How About a String?&lt;/h3&gt;
&lt;p&gt;
    A string value might &lt;em&gt;seem&lt;/em&gt; to be iterated over (with some practical usefulness). In that case, a String &lt;em&gt;object&lt;/em&gt; would be created, holding the original string 
    value; you wouldn&#39;t actually be iterating over a string value; it would just &lt;em&gt;seem&lt;/em&gt; like it. 
&lt;/p&gt;

&lt;p&gt;
    The difference between a &lt;code&gt;String&lt;/code&gt; object and a string value, is explained in my entry &lt;a href=&quot;http://dhtmlkitchen.com/?category=/JavaScript/&amp;amp;date=2007/10/05/&amp;amp;entry=How-Property-Access-Works&quot;&gt;How Property Access Works&lt;/a&gt;.
&lt;/p&gt;


&lt;h3&gt;Practical Example of Iteration&lt;/h3&gt;
&lt;p&gt;Objects which support some form of sequential indexing of properties can be practically iterated over (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-12.6.3&quot; 
	title=&quot;The for Statement&quot;&gt;&amp;#167;12.6.3&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;
    JavaScript provides two types of built-in objects that fit that description. 
&lt;/p&gt;

&lt;dl&gt;
    &lt;dt&gt;String&lt;/dt&gt;
    &lt;dd&gt;Property values are characters. indexed by a numerical String starting at &lt;code&gt;&quot;0&quot;&lt;/code&gt;&lt;/dd&gt;
    &lt;dt&gt;Array&lt;/dt&gt;
    &lt;dd&gt;Property values are anything. Indexed by a numerical String starting at &lt;code&gt;&quot;0&quot;&lt;/code&gt;&lt;/dd&gt;
&lt;/dl&gt;

&lt;h3&gt;Iterate over an Array&lt;/h3&gt;

&lt;p&gt;
    An &lt;code&gt;Array&lt;/code&gt; is an object 
	that is specialized by its &lt;code&gt;length&lt;/code&gt; property, it&#39;s &lt;code&gt;[[put]]&lt;/code&gt; method, 
	and its literal initializer syntax. &lt;code&gt;Array.prototype&lt;/code&gt; is sometimes modified 
    to add features that are not supported in certain browsers (like &lt;a href=&quot;http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6#Array_extras&quot;&gt;Array Extras&lt;/a&gt;, supported 
    in Webkit and Gecko, but not Opera 9.2  or IE 7).
&lt;/p&gt;

&lt;p&gt;
	Because &lt;code&gt;Array.prototype&lt;/code&gt; is often modified, &lt;a
	href=&quot;http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/&quot;
	&gt;it is not safe to enumerate over an &lt;code&gt;Array&lt;/code&gt;&lt;/a&gt; (unless you have a &lt;a 
	href=&quot;http://hexmen.com/blog/2006/12/iterating-over-sparse-arrays/&quot;&gt;sparse array&lt;/a&gt; and know how &lt;code&gt;hasOwnProperty&lt;/code&gt; works).
&lt;/p&gt;

&lt;p&gt;
    Non existent properties that need to be added by programmer-defined code do not exist, and therefore, cannot have the &lt;code&gt;DontEnum&lt;/code&gt; attribute. 
    For example, &lt;code&gt;Array.prototype.some&lt;/code&gt; does not exist on &lt;code&gt;Array.prototype&lt;/code&gt; in IE or Opera, but is non-enumerable, 
    native code in other browsers. 
&lt;/p&gt;
&lt;p&gt;To avoid enumerating over a property in the prototype chain, a cautious programmer will avoid using &lt;code&gt;for in&lt;/code&gt; on an Array, and use &lt;code&gt;hasOwnProperty&lt;/code&gt; when he does use &lt;code&gt;for in&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;    Library authors might consider adding only the top-level Extras, e.g. &lt;code&gt;Array.some&lt;/code&gt; to browsers that don&#39;t have &lt;code&gt;Array.some&lt;/code&gt;, and leaving the prototype alone. 
&lt;/p&gt;

&lt;h3&gt;Iterating Over a String&lt;/h3&gt;

&lt;p&gt;
    When the string value 
    is converted to a String Object, the characters in the value are accessible through the object. 
&lt;/p&gt;

&lt;p&gt;
    &lt;code&gt;String.prototype&lt;/code&gt; has a method to access character properties: &lt;code&gt;charAt&lt;/code&gt; (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-15.5.4.4&quot; 
	title=&quot;String.prototype.charAt&quot;&gt;&amp;#167;15.5.4.4&lt;/a&gt;). 
&lt;/p&gt;

&lt;p&gt;
    Here&#39;s where it gets interesting.
&lt;/p&gt;

&lt;p&gt;
    Gecko and Webkit implement &lt;em&gt;another&lt;/em&gt; way access to String index 
    properties: The property access operators &lt;code&gt;[ ]&lt;/code&gt;. This is not part of the official specification. 
&lt;/p&gt;
&lt;p&gt;  
    String&#39;s &lt;code&gt;[[Put]]&lt;/code&gt; method &lt;a href=&quot;http://bclary.com/2004/11/07/#a-8.6.2.2&quot; title=&quot;8.6.2.2 [[Put]](P, V)&quot;&gt;&amp;#167;8.6.2.2&lt;/a&gt; is specialized in Webkit. This seems to create some problems, as can be shown in an example.
&lt;/p&gt;
&lt;h3&gt;Example Using &lt;code&gt;[]&lt;/code&gt; on a String object&lt;/h3&gt;
&lt;pre id=&#39;magic-string-source&#39;&gt;(function(){
    String.prototype[&#39;2&#39;] = &quot;prot&quot;;
    String.prototype[&#39;4&#39;] = &quot;prot4&quot;;
    a = new String(&quot;012&quot;);
    a[1] = &quot;one&quot;;
    a[11] = &quot;eleven&quot;
    var result = [];
    for(var i = 0; i &amp;lt; a.length; i++)
        result.push(a.charAt(i) + &quot;, a[&#39;&quot;+i+&quot;&#39;] = &quot;+ a[i]);

    result.push(a.charAt(4)  // Should be &quot;&quot;.
        + &quot; , a[&#39;&quot;+ 4 +&quot;&#39;] = &quot;+ a[4] );
    
    result.push(a.charAt(11)  // Should be &quot;&quot;.
        + &quot; , a[&#39;&quot;+ 11 +&quot;&#39;] = &quot;+ a[11] );

    return result.join(String.nl);
})();
&lt;/pre&gt;
&lt;button onclick=&quot;assertEquals(&#39;magic-string&#39;);&quot;&gt;eval&lt;/button&gt;

&lt;table class=&quot;result&quot; style=&quot;width: 42em;&quot;&gt;
	&lt;tbody class=&quot;pre&quot;&gt;
        &lt;tr&gt;
            &lt;th&gt;Result&lt;/th&gt;
            &lt;th&gt;Expected&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td id=&quot;magic-string-result&quot; class=&quot;noresult&quot;&gt;                                            &lt;/td&gt;
            &lt;td id=&quot;magic-string-expected&quot;&gt;0, a[&#39;0&#39;] = 0
1, a[&#39;1&#39;] = one
2, a[&#39;2&#39;] = 2
, a[&#39;4&#39;] = prot4
, a[&#39;11&#39;] = eleven&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;table border=&quot;1&quot; class=&quot;result&quot; style=&quot;font-size: smaller&quot;&gt;
	&lt;thead&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot; style=&quot;display:none&quot;&gt;Browser:&lt;/th&gt;
			&lt;th&gt;Internet Explorer&lt;/th&gt;
			&lt;th&gt;Mozilla&lt;/th&gt;
			&lt;th&gt;Opera 9.2&lt;/th&gt;
			&lt;th&gt;Safari 3&lt;/th&gt;
		&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot; style=&quot;display:none&quot;&gt;Result:&lt;/th&gt;
            &lt;td class=&quot;incorrect&quot;&gt;0, a[&#39;0&#39;] = undefined
1, a[&#39;1&#39;] = one
2, a[&#39;2&#39;] = prot
, a[&#39;4&#39;] = prot4
, a[&#39;11&#39;] = eleven&lt;/td&gt;
			&lt;td&gt;0, a[&#39;0&#39;] = 0 
1, a[&#39;1&#39;] = one 
2, a[&#39;2&#39;] = 2 
, a[&#39;4&#39;] = prot4 
, a[&#39;11&#39;] = eleven&lt;/td&gt;
			&lt;td&gt;0, a[&#39;0&#39;] = 0
1, a[&#39;1&#39;] = one
2, a[&#39;2&#39;] = 2
 , a[&#39;4&#39;] = prot4
 , a[&#39;11&#39;] = eleven&lt;/td&gt;
			&lt;td class=&quot;incorrect unexpected&quot;&gt;0, a[&#39;0&#39;] = 0
1, a[&#39;1&#39;] = 1
2, a[&#39;2&#39;] = 2
, a[&#39;4&#39;] = prot4
, a[&#39;11&#39;] = eleven&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;
    &lt;code&gt;String.prototype.charAt&lt;/code&gt; works consistently in all browsers. The property access operator results are more interesting.
&lt;/p&gt;

&lt;p&gt;
    In Gecko and Opera, property access (&lt;code&gt;[]&lt;/code&gt;, &lt;a href=&quot;http://bclary.com/2004/11/07/#a-11.2.1&quot;&gt;&amp;#167;11.2.1&lt;/a&gt;) on a &lt;code&gt;String&lt;/code&gt; checks the object for a property by the name given. If no property is found, if the string value of the property name is integral, &lt;code&gt;charAt&lt;/code&gt; (or its equivalent) is called, passing 
    the property, e.g &lt;code&gt;aString[1.0]&lt;/code&gt; is evaluated as &lt;code&gt;aString[&#39;1&#39;]&lt;/code&gt; (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-15.5.4.4&quot; 
	title=&quot;String.prototype.charAt&quot;&gt;&amp;#167;15.5.4.4&lt;/a&gt;). 
&lt;/p&gt;
&lt;p&gt;
    Webkit has the opposite result. Webkit seems to have broken &lt;code&gt;[[Put]]&lt;/code&gt; for &lt;code&gt;String&lt;/code&gt;.
&lt;/p&gt;

&lt;h4&gt;Observations on Property Access&lt;/h4&gt; 


&lt;h5&gt;Mozilla and Opera&lt;/h5&gt;
 &lt;ul&gt;
	&lt;li&gt;&lt;code&gt;a[&#39;0&#39;]&lt;/code&gt; returns the character at index &lt;code&gt;0&lt;/code&gt;, &quot;0&quot;. (goes through &lt;code&gt;charAt&lt;/code&gt;) &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a[&#39;1&#39;]&lt;/code&gt; is resolved to a property, the value &quot;one&quot; is returned.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;a[&#39;2&#39;]&lt;/code&gt; does not find a property on the object itself and does not call &lt;code&gt;[[Get]]&lt;/code&gt;. &lt;code&gt;charAt&lt;/code&gt; is called.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;a[&#39;11&#39;]&lt;/code&gt; is resolved to a property, the value &quot;one&quot; is returned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
    Gecko&#39;s &lt;code&gt;[[Put]]&lt;/code&gt; results in a property being added to the object. The property will not be returned 
    in &lt;code&gt;charAt&lt;/code&gt;, but will be returned with &lt;code&gt;[ ]&lt;/code&gt; (&lt;a 
 href=&quot;http://bclary.com/2004/11/07/#a-11.2.1&quot; 
	title=&quot;11.2.1 Property Accessors&quot;&gt;&amp;#167;11.2.1&lt;/a&gt;). 
&lt;/p&gt;


&lt;h5&gt;Webkit&lt;/h5&gt;
&lt;p&gt;
    Webkit seems to have a special algorithm for &lt;code&gt;[[Put]]&lt;/code&gt; on String. A property &lt;var&gt;P&lt;/var&gt; seems to be added 
    to a &lt;code&gt;String&lt;/code&gt; only when &lt;code&gt;ToNumber(&lt;var&gt;P&lt;/var&gt;)&lt;/code&gt; is greater than the String&#39;s length. 
&lt;/p&gt;


&lt;p&gt;
    The approach Webkit takes is a bad one. 
    I cannot see any reason why the Webkit team did this. A specialized &lt;code&gt;[[Put]]&lt;/code&gt; might be the result of the design under the hood and was a preventative 
    measure to keep the string from being modified (guess).
&lt;/p&gt;

&lt;p&gt;
    Unlike an &lt;code&gt;Array&lt;/code&gt;, 
    a &lt;code&gt;String&lt;/code&gt;&#39;s &lt;code&gt;length&lt;/code&gt; property is &lt;code&gt;ReadOnly&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
So we&#39;ve covered enumerating over a primitive (useless), iterating over an String and an Array. What about iterating over an object?
&lt;/p&gt;
&lt;h3&gt;Iterate over an Object&lt;/h3&gt;
&lt;p&gt;
    Its not usually practical, but it is &lt;em&gt;possible&lt;/em&gt;
&lt;/p&gt;
&lt;pre&gt;
var nlist = {
  n : 1,
  nn: 2,
  nnnn: 3,
  nnnnnnnn: 3
};

if(! &quot;console&quot; in window) {
    document.title = &quot;log: &quot;;
    window.console = { log : function(s){ document.title += s; };
}
var result = &quot;&quot;;
for( var p = &quot;