<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1482295281150166231</id><updated>2024-09-04T03:55:17.884-07:00</updated><category term="js"/><category term="code"/><category term="diary"/><category term="proxy"/><category term="tips"/><category term="events"/><category term="ie"/><category term="brief"/><category term="demo"/><category term="debug"/><category term="es5"/><category term="git"/><category term="money"/><category term="smartypig"/><category term="w3c"/><title type='text'>What I&#39;ve Learned</title><subtitle type='html'>&lt;strike&gt;A diary of discoveries.&lt;/strike&gt;&#xa;&lt;br&gt;&#xa;Lessons, in life and online, I&#39;ll never remember.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-6494584637832612244</id><published>2011-12-08T09:44:00.001-08:00</published><updated>2011-12-08T09:48:07.675-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="brief"/><category scheme="http://www.blogger.com/atom/ns#" term="diary"/><title type='text'>Too many drafts</title><content type='html'>It&#39;s come to the point that I have more drafts than published posts in my account... and life isn&#39;t slowing down. I&#39;ve started a new job, am expecting a new baby (my first), and there&#39;s still a lot I need to figure out. Writing doesn&#39;t come easy for me, but I thought to post something that gets the ball rolling. More to come!</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/6494584637832612244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2011/12/too-many-drafts.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6494584637832612244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6494584637832612244'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2011/12/too-many-drafts.html' title='Too many drafts'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-5996391948780278521</id><published>2011-03-09T22:57:00.000-08:00</published><updated>2011-03-09T22:57:14.121-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy"/><category scheme="http://www.blogger.com/atom/ns#" term="tips"/><title type='text'>Passing Second-Class Arguments</title><content type='html'>Before it&#39;s current incarnation, I was frustrated by my own, &lt;a href=&quot;http://learnings-bemson.blogspot.com/2011/02/proxy-and-es5-harmony-proxy.html&quot;&gt;soon-to-be-renamed&lt;/a&gt;, &lt;a href=&quot;https://github.com/bemson/Proxy&quot;&gt;Proxy object&lt;/a&gt;. [Mind you, I don&#39;t mean the upcoming &lt;a href=&quot;http://wiki.ecmascript.org/doku.php?id=harmony:proxies&quot;&gt;E5 Proxy object&lt;/a&gt;.] As a function manager, Proxy offers the benefit of passing secondary execution information, to it&#39;s managed routines. (These &quot;extra&quot; arguments permit comprehensive forking.) As with many function managers, this well-intentioned practice wound up restricting the number of arguments allowed in managed routines, resulting in a &lt;i&gt;polluted signature&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;Determining when a signature is polluted can be difficult, since such judgement is subject to the code&#39;s intended use - not it&#39;s explicit structure. For example, within an event-dispatch context, an argument signature is expected (if not required) by the handler routines - in order to properly process data from the dispatched event. On the other hand, I discovered that Proxy had a polluted signature, only after using it with a non-conforming routine. Thus, it&#39;s the problem-domain which reveals whether the solution suffers from this type of symptom.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;The Subtle Condition&lt;/span&gt;&lt;br /&gt;
To clarify the problem, let&#39;s invent a silly function manager. (For arguments sake, I&#39;m reducing the concept of function &quot;manager&quot; to any routine that calls another using the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;apply&lt;/span&gt; or &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;call&lt;/span&gt; methods.) Below is an example of such a routine - I&#39;ve named it &quot;Silly&quot; - which sends secondary information (albiet trifling) to the function(s) it calls (or &quot;manages&quot;).&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;function Silly(fnc) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var num = 5,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;rand = Math.random();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return fnc.call(this, arguments[0], num, rand);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;/span&gt;&lt;/blockquote&gt;You can see that &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt; will invoke &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;fnc&lt;/span&gt;, passing one &lt;i&gt;given&lt;/i&gt; argument while adding two of it&#39;s own values (&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;num&lt;/span&gt; and &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;rand&lt;/span&gt;). The example demonstrates an organic principle of JavaScript functions: argument order connotes primacy. Many function managers take advantage of this principle, in order to distinguish &quot;extra&quot; from &quot;core&quot; arguments, in their calls to external functions. For instance, below is line 870 in attribute.js, of &lt;a href=&quot;http://developer.yahoo.com/yui/3/attribute/&quot;&gt;YUI 3&#39;s Attribute Object&lt;/a&gt; (version 3.3.0).&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;retVal = setter.call(host, newVal, name);&lt;/span&gt;&lt;/blockquote&gt;The line above calls an external function which can (according to their documentation) &quot;manipulate the value which is stored for the attribute.&quot; In this case, &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;newVal&lt;/span&gt; is the core argument - to be tested and manipulated. However, &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;name&lt;/span&gt; is passed after the core argument. Again, the data is passed to support robust functionality, but is definitely not &lt;i&gt;central&lt;/i&gt; to functionality.&lt;br /&gt;
&lt;br /&gt;
In and of itself, there is nothing inherently wrong or dangerous in either example. Since it is the problem-domain which reveals the issue, let&#39;s now use &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt;&amp;nbsp;to create two functions (rather augment two closures). One will reveal when our mandated signature becomes a pollutted signature.&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;var stringify = Silly(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;function (x) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return x + &#39;&#39;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
);&lt;br /&gt;
stringify(5); // -&amp;gt; &#39;5&#39;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;var sum = Silly(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;function sum(x, y) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return isNaN(x + y) ? 0 : x + y;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
);&lt;br /&gt;
sum(5, 20); // -&amp;gt; 10&lt;/span&gt;&lt;/blockquote&gt;While the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;stringify&lt;/span&gt; function is fine, the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sum&lt;/span&gt; function is now broken, or - at least - not working as designed. Because &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt; only passes the first given argument, it greatly impacts the output of it&#39;s managed routines. Sure, that&#39;s not good, but how can we tell which function needs fixing? More to the point: How can a function pass non-critical arguments without impacting the arguments expected by the routines it invokes?&lt;br /&gt;
&lt;br /&gt;
Regarding the first question. Were our example intended to work with any routine, then we can safely state that &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt; has failed, and suffers from a polluted signature. However, were there documentation stating the limitations our routine placed on called functions, then our &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sum&lt;/span&gt; function would be the culprit... The line is blurry, because the structure of our code doesn&#39;t hint to either intention. Drawing that line in documentation (or worse, comments) is the last place we want to write code. We&#39;d like that line to be self-evident in the code&#39;s structure.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Clarifying Code Structure&lt;/span&gt;&lt;br /&gt;
The problem is that most managing functions attempt to communicate an argument&#39;s relevance with it&#39;s order; an abuse of the order-equates-primacy principle. That is, the greater the arguments index the less a called routine should consider it within it&#39;s logic.&amp;nbsp;This is how our&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt;&amp;nbsp;function works, along with earlier versions of Proxy, and (perhaps even) YUI&#39;s Attribute Object.&lt;br /&gt;
&lt;br /&gt;
The truth is that there are no &lt;i&gt;secondary&lt;/i&gt; arguments in a single arguments object. You might think of it as an overriding principle: all arguments should be useful. After all, arguments exist to impact the logic of a function. Otherwise, what are they arguing &lt;i&gt;for&lt;/i&gt; (excuse the poor pun)? Nevertheless, order communicates primacy. With the arguments object, relevance is given by inclusion alone.&lt;br /&gt;
&lt;br /&gt;
While trying to solve this same problem in Proxy - using order alone - I ran through a number of options. (Mind you, my final option was to document it&#39;s proper usage, and move on.) I&#39;ll sum them up with our example function, below. None of these variations net a &lt;i&gt;less&lt;/i&gt; polluted signature in &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt;, because all continue to require that called functions use a specific signature. Nonetheless, I&#39;ve listed them below.&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// pass all given arguments as the first argument&lt;br /&gt;
function Silly(fnc) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var&amp;nbsp;num = 5,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;rand = Math.random();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return fnc.apply(this, [arguments, num, rand]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;br /&gt;
// prepend a variable number of arguments&lt;br /&gt;
function Silly(fnc) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var args = [].slice.call(arguments),&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;rand = Math.random();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return fnc.apply(this, args.concat(num, rand));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;br /&gt;
// append a variable number of arguments&lt;br /&gt;
function Silly(fnc) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var args = [].slice.call(arguments),&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;num = 5,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;rand = Math.random();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return fnc.apply(this, [num,rand].concat(args));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;/span&gt;&lt;/blockquote&gt;In all cases, the code structure does not communicate the relevancy of the &quot;extra&quot; arguments. In fact, once passed to a called function, attempts to distinguish &quot;core&quot; from &quot;extra&quot; arguments (using order alone) are blurred. Thankfully, there&#39;s more to an arguments &lt;i&gt;object&lt;/i&gt;&amp;nbsp;than it&#39;s values...&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Using the Call-Stack&lt;/span&gt;&lt;br /&gt;
The call-stack is a temporal structure, accessible (oddly enough) via the arguments object itself. Accessed by a jungle of &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;callee&lt;/span&gt; and &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;caller&lt;/span&gt; properties, any function can reference it&#39;s calling function (and &lt;i&gt;it&#39;s&lt;/i&gt; calling function, etc.) - all via the arguments object.&lt;br /&gt;
&lt;br /&gt;
Each &quot;step&quot; thru the call-stack goes backwards, to a function which is waiting to complete. Each stacked function (like any executing function) has it&#39;s own arguments object (containing the values it was initially passed). The farther back one goes, the less relevance that stacked function would have on the logic of the one executing. Thus, the call-stack is a structure for identifying relevance.&lt;br /&gt;
&lt;br /&gt;
By executing a closure, before calling a managed function, and passing it non-critical data, our example function can now work with any routine.&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;function Silly(fnc) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var that = this,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;args = arguments,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;num = 5,&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;rand = Math.random();&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return (&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;function () {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return fnc.apply(that, args)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;)(num, rand)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Silly&lt;/span&gt; now passes all given arguments to the managed routine, which can access the tiered or second-class arguments as it sees fit.&amp;nbsp;Of course, this insertion of secondary (or second-class) arguments in the call-stack will require extracting. Though our old &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sum&lt;/span&gt; routine would now work just fine, it could be recoded as follows, to include the second-class data in it&#39;s logic:&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;var sum = Silly(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;function sum(x, y) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;var sArgs = arguments.caller.callee.arguments;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;return isNaN(x + y) ? (sArgs[1] || sArgs[0]) : x + y;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
);&lt;/span&gt;&lt;/blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Conclusions&lt;/span&gt;&lt;br /&gt;
By using the call-stack, non-critical, execution-only data &lt;i&gt;can&lt;/i&gt; be passed to a function indirectly. The routines managed by functions that employ this technique will need to change their logic, in order to access this second-tier of data - or, second-class arguments. However, eliminating polluted signatures, reducing an API&#39;s dependence on them, makes for flexible, clearly-structured code with a longer shelf-life.&lt;br /&gt;
&lt;br /&gt;
I&#39;ve done no performance research on the impact from unnecessarily increasing the call-stack in this manner. I am sure this technique does impact memory footprints and processing power, but suspect it&#39;s negligible, compared to the aforementioned gains.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Epilogue&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Naturally, second-class arguments have vastly improved the usefulness and expanded the application of my own Proxy code. However, I quickly realized that the process of extracting this data was tasking and bothersome.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Thus, I defined a static method for Proxy, called &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;a href=&quot;https://github.com/bemson/Proxy/wiki/Proxy-API&quot;&gt;getContext&lt;/a&gt;&lt;/span&gt;. The method takes a function&#39;s arguments object and does all the long syntax to build object-literal containing the second-class data. So instead of Proxy users having to target index 1 from &quot;arguments.callee....&quot; in order to get the &quot;alias&quot; value, they can simply use this line within the functions given to Proxy.&lt;/div&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;var alias = Proxy.getContext(arguments).alias;&lt;/span&gt;&lt;/blockquote&gt;If you&#39;re a library author who uses managing functions, I highly recommend a similar convenience method if you employ this technique!</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/5996391948780278521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2011/03/passing-second-class-arguments.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/5996391948780278521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/5996391948780278521'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2011/03/passing-second-class-arguments.html' title='Passing Second-Class Arguments'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-6285190135601636065</id><published>2011-02-23T11:09:00.000-08:00</published><updated>2011-02-23T11:09:26.359-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="diary"/><category scheme="http://www.blogger.com/atom/ns#" term="es5"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy"/><title type='text'>Proxy and the ES5 (Harmony) Proxy</title><content type='html'>I didn&#39;t know it then, but &lt;b&gt;Proxy &lt;/b&gt;is a native object in ECMA-Script 5 (ES5), the next web programming language. What this means is that I must change the name of my Proxy object to something else - yet to be determined. Moreover, I&#39;m sure there will be inquiries (from all two of you) about the differences and similarities between my Proxy object and &quot;theirs&quot;.&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Approved in 2009, much of &lt;a href=&quot;http://kangax.github.com/es5-compat-table/&quot;&gt;ES5 is supported by several current and upcoming browsers&lt;/a&gt;. However, the Proxy object didn&#39;t seem to get much attention until mid 2010. To date, &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/New_in_JavaScript/1.8.5#New_Objects&quot;&gt;FireFox 4&lt;/a&gt; is the only browser supporting the ES5 Proxy API (with their own extensions, natch). Still, it&#39;s here and clearly my work&#39;s namesake is in the shadows of a looming standard.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Thus, the tangible similarity between ES5 and my work is the namespace &quot;Proxy&quot;. An intangible similarity is the overlapping purpose of both objects. Both provide wrappers to &quot;base&quot; objects, for security, simplicity... many of the benefits described in the &lt;a href=&quot;http://wiki.ecmascript.org/doku.php?id=harmony:proxies&quot;&gt;ES5 wiki for Proxy&lt;/a&gt;. Actually, I&#39;m rather glad there is language to describe and capture why such an object is needed in web programming - a difficult task for me. I&#39;ll be sure to update my wiki pages to reflect the shared intentions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Everything &lt;i&gt;else&lt;/i&gt; between my Proxy and ES5&#39;s is different, however. After all, it&#39;s an entirely new language, using constructs unavailable to the environment that my Proxy object was designed for. My work is still a viable alternative to &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Defining_Getters_and_Setters&quot;&gt;native getters and setters&lt;/a&gt;, and will continue to be for older browsers that don&#39;t support ES5 - which makes heavy use of these and other new constructs. Must be nice designing a language...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Does my Proxy object do anything ES5&#39;s doesn&#39;t? From what I&#39;ve read so far - and I&#39;m not claiming to be an expert, ES5&#39;s Proxy is a one-way street. That is, there doesn&#39;t seem to be a way to capture the source object - what they refer to as the &quot;subject&quot; - from a given ES5 Proxy. Therefore, one could return a Proxy (of either type), but only mine allows extracting the subject again for further manipulation. My Proxy does so securely, using a signature object.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The hardest part: parting with the name. Obviously, I can&#39;t keep calling my object a &quot;Proxy&quot;. Granted, the term &quot;proxy&quot; is generic enough. Even after you isolate it to programming, it still has a variety of meanings and applications. I&#39;ve considered &quot;Alias&quot;, &quot;Mirage&quot; or &quot;Mirror&quot; (to flatter &lt;a href=&quot;http://soft.vub.ac.be/amop/at/tutorial/reflection#mirages&quot;&gt;AmbientTalk &lt;/a&gt;- I think they had a hand with writing/inspiring the ES5 Proxy draft). Of course, I&#39;m open to suggestions from readers.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;One driver to change the name, is my latest project: &lt;a href=&quot;https://github.com/bemson/Flow&quot;&gt;Flow&lt;/a&gt;. I hope to present and blog about soon, but know that it uses my Proxy object extensively. In some cases, that project would do better using the ES5 Proxy - assuming better&amp;nbsp;performance and less memory. I&#39;ll save discussing that project for another day... First, I&#39;m going to make sure that name isn&#39;t slated for another ECMA-Script standard!&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/6285190135601636065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2011/02/proxy-and-es5-harmony-proxy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6285190135601636065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6285190135601636065'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2011/02/proxy-and-es5-harmony-proxy.html' title='Proxy and the ES5 (Harmony) Proxy'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-2111029404722684501</id><published>2010-12-21T13:32:00.000-08:00</published><updated>2010-12-21T13:32:20.224-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="tips"/><title type='text'>Clear options in a MULTI-SELECT field without loops</title><content type='html'>If I&#39;ve published anything that qualifies as a &quot;tweet&quot;, this post does. Though I have been busy, it has been a while and I sorely miss blogging. With the holidays all around us, small posts make for published posts.&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Perhaps I&#39;ve never had to auto-select OPTION elements in a multi-SELECT field, but I discovered a simple method for doing so, that was worth noting.&lt;/div&gt;&lt;div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;I&amp;nbsp;had a multi-select field and needed to select various options, based on the numeric indexes from another array. Before looping through the array of options (to select), I needed to ensure the form field had no previously selected options present.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Since the options property of a select field, is like an array, I first thought to iterate over them with a for-loop, but then I&#39;d have two loops...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// deselect all options&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;for (var i = 0; select.options[i]; i++) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select.options[i].selected = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// select the targeted options&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;for (var i = 0, j = targets.length; i &amp;lt; j; i++) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select.options[targets[i]].selected = 1;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I don&#39;t like looping through overlapping collections - such as select.options and then the list of target options...&amp;nbsp;Maybe a nested loop? Well, that means even more wasted cycles, since the browser is processing the same array multiple times.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// loop through all options&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;for (var i = 0; select.options[i]; i++) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// deselect this option&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select.options[i].selected = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;// loop through all targets&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;for (var q = 0, z = targets.length; q &amp;lt; z; q++) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// if the option should be selected...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (i == targets[q]) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select.options[i].selected = 1;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break; // exit this nested loop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So that idea was out - if not, undesired. If your thinking cap is on, you&#39;ve wondered aloud about the selectedIndex property of the select field. This index is mostly used with single-select fields (aka, the drop-down menu), to dynamically select an option. Happily, it works the same way for a multi-select field, with the added benefit of deselecting all other options.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// select the first option&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;select.selectedIndex = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// deselect the first option&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;select.options[0].selected = 0;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;// select the targeted options&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;for (var i = 0, j = targets.length; i &amp;lt; j; i++) {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;select.options[targets[i]].selected = 1;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;So we select the first option (doesn&#39;t matter which really), then immediately deselect it. Library authors would ensure there is a zero-indexed option to select-then-deselect, first. Also, I don&#39;t know if a repaint or redraw occurs when toggling active options - so you might hide it via css before doing all of this.Though we do loop through an array next (to select certain options), we avoid the initial/nested loop scenario. Pretty simple!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Yes, the solution takes less time than writing a blog post. I needed to get back in the swing of things (or I&#39;d never blog again). If the new year is kind and time permits, I hope to blog about my next adventure into open-source this January!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Happy-everything all!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/2111029404722684501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/12/clear-options-in-multi-select-field.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/2111029404722684501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/2111029404722684501'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/12/clear-options-in-multi-select-field.html' title='Clear options in a MULTI-SELECT field without loops'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-7223672959482256961</id><published>2010-09-12T17:22:00.000-07:00</published><updated>2010-09-12T17:25:10.820-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="diary"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy"/><title type='text'>Learning to Open-Source via Proxy</title><content type='html'>The Internet is a relentless, fast-paced, consumer of content, and I&#39;m a bit of a recluse. My engagements had been brief and trifling; irc chatting, a blog comment here, a forum post there. Then, as a test use of github.com - a popular code-sharing service - I published &lt;a href=&quot;http://github.com/bemson/Proxy&quot;&gt;Proxy&lt;/a&gt;. It was my debut in the open-source JavaScript world&lt;sup&gt;&lt;small&gt;&lt;a href=&quot;#footnote&quot;&gt;1&lt;/a&gt;&lt;/small&gt;&lt;/sup&gt;, and I was determined to see it through to the end. However, in the reverse time-warp that is the Internet, I&#39;ve learned that the end never comes...&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
So here you are, now, reading about code I&#39;d rather move past. &quot;Now&quot; could be the day I posted this article, but it&#39;s more likely some months or years later. Admittedly, I promised to discuss Proxy, and my efforts to document it, in an earlier post. &lt;i&gt;Now&lt;/i&gt; felt like a good time.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Introducing Proxy&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Proxy allows you - the JavaScript developer - to share and use privileged objects easily. (A privileged object has functions that execute within a scope different from the current one.) Proxy began within a larger project that has a public API of privileged objects. Each privileged object uses getter and setter styled methods to manipulate it&#39;s private-object counterpart. As I optimized and refactored that code, a pattern emerged for defining these getter/setter methods, which is now employed by the Proxy constructor.&lt;br /&gt;
&lt;br /&gt;
Before I continue, it&#39;s important to note the differences between Proxy and &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Defining_Getters_and_Setters&quot;&gt;native getters and setters.&lt;/a&gt; First, the native option uses a recent JavaScript construct - supported by all modern browsers except Internet Explorer (natch). Syntax aside, they also have different applications. The native method is designed to mask an object&#39;s individual properties, while Proxy is designed to mask the entire object. With a compliant browser, you can do the latter with the former, but not vice-versa. Ultimately, given their distinct application, I won&#39;t compare these two in this article.&lt;br /&gt;
&lt;br /&gt;
To be clear, Proxy is nothing new or unique. But that&#39;s because creating versions of objects - or proxy-like objects - is also not new or unique. If you were tasked to create proxy-like objects in code, it might go something like this. Define a function that makes an object literal that has methods to get and set properties of some source object. Here&#39;s an example, below.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://gist.github.com/576620.js?file=traditional-proxy-creation.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Simple enough, and there is already a perceptible degree of repetition in the defined methods. If you had to do this for more than one property, you might refactor it like below.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://gist.github.com/576620.js?file=refactored-proxy-creation.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Proxy takes this one step further, by identifying three phases of our getter and setter functions: get, vet, and set or &lt;i&gt;GVS&lt;/i&gt;. The get and set phases isolate when a getter/setter retrieves or assigns a value. The vet phase isolates when a setter function is validating a value, before assigning it to the source object&#39;s property. With this abstraction, we can describe each phase of our getter/setter function with an object. Proxy uses an indexed array, called a GVS array, where each index corresponds to each phase - the first is the &quot;get-index&quot;, and so on. Proxy accepts and compiles GVS arrays, so they execute like traditional getter/setter methods.&lt;br /&gt;
&lt;br /&gt;
Each index can be a string, function, or any other truthy or falsy value. When the get and set indexes are strings, they reference the source object property to retrieve and assign, respectively. When the vet-index is a string, it specifies the object type required in order to set a value. [The next version of Proxy will accept an array of object types.] For the sake of comparison, below is a traditional proxy-like object, with a same-name setter/getter function that retrieves property &quot;x&quot; and accepts a number for property &quot;y&quot;, and the same function described as a GVS array in a Proxy constructor.&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://gist.github.com/576620.js?file=function-gvs-comparison.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
There are many possibilities for defining simple to complex getter/setter functions via a Proxy GVS array. (The Proxy wiki &lt;i&gt;will&lt;/i&gt; be updated to explain all of them.) Of course, Proxy doesn&#39;t limit you to GVS arrays, and can accept regular functions as well. However, the efficiency of the GVS pattern is the primary reason I use it, instead of defining proxy-like objects traditionally.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Learning to do it right (next time)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Open-sourcing takes work and a greater commitment than open-source advocates proselytize. Documenting Proxy, improving it, defending it, naming and explaining concepts like &quot;GVS pattern&quot; have destroyed my productivity. Before announcing Proxy, I spent a weeks documenting it (i.e., less than two-hundred lines of &lt;i&gt;commented&lt;/i&gt; code). Now, a month later, I&#39;ve finally come around to blogging about it directly, if not completely.&lt;br /&gt;
&lt;br /&gt;
This post doesn&#39;t mark the end of anything regarding Proxy. I&#39;ve resigned myself to the fact that this code is my baby and always will be. I&#39;ve begun to integrate Proxy updates into the larger project it spawned from. I also have plans to improve it&#39;s documentation and packaging - which will finally include unit tests. I&#39;ve filed tickets against myself (a highly recommended practice), and plan to add a roadmap to the wiki.&lt;br /&gt;
&lt;br /&gt;
Though Proxy is more than I expected, it&#39;s just what I asked for: a trial run at open-sourcing my work. I&#39;ve de-romanticized the notion of shared code equating to &lt;i&gt;community-supported&lt;/i&gt; code. That kind of interest and support comes way down the line, after &lt;a href=&quot;http://www.reddit.com/r/javascript/comments/d34qt/proxy_getters_and_setters_for_js/&quot;&gt;useful criticism and outright derision.&lt;/a&gt; By dragging Proxy (and myself) to higher levels of recognition and professionalism, I&#39;m discovering what it might take to push larger projects, in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&quot;footnote&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;sup&gt;&lt;small&gt;1&lt;/small&gt;&lt;/sup&gt; Actually, &lt;a href=&quot;http://www.codingforums.com/showthread.php?t=4577&quot;&gt;my first JavaScript routine&lt;/a&gt; was posted to &lt;a href=&quot;http://codingforums.com/&quot;&gt;codingforums.com&lt;/a&gt; in 2002. A message-board is &lt;i&gt;not&lt;/i&gt; a code-sharing service per se, yet my code remains archived and accessible to this day.</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/7223672959482256961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/09/learning-to-open-source-via-proxy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7223672959482256961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7223672959482256961'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/09/learning-to-open-source-via-proxy.html' title='Learning to Open-Source via Proxy'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-7980603489540097162</id><published>2010-08-20T11:00:00.000-07:00</published><updated>2010-08-20T12:50:12.717-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="tips"/><title type='text'>The smallest boolean in JavaScript</title><content type='html'>One of my projects has a pretty large API, with lots of methods returning boolean values. At first, I returned 1&#39;s and 0&#39;s - which are not actual booleans, but are certainly good enough (for most applications).&amp;nbsp;However, for a &lt;i&gt;public&lt;/i&gt; API, I knew they would need to return &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt; or &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;... After making the edits, my file size jumped. Which is how I found the smallest boolean in JavaScript.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
JavaScript coders have used boolean variations and equivalents since the language&#39;s inception.&amp;nbsp;No matter an object&#39;s type, it can be a boolean.&amp;nbsp;They are about the nicest values out there! There are &lt;a href=&quot;http://11heavens.com/falsy-and-truthy-in-javascript&quot;&gt;truthy and falsy booleans&lt;/a&gt;, primitive boolean values, and Boolean objects - which aren&#39;t really booleans, but can be used in boolean comparisons.&amp;nbsp;Then there are JavaScript expressions, which can &lt;i&gt;also&lt;/i&gt; be booleans.&lt;br /&gt;
&lt;br /&gt;
My habit with boolean expressions, was to return the inverse of some variable at the end of a function. As in, initialize a boolean flag (that is, any variable with a boolean value), then invert it&#39;s value before returning it. This silly function below, illustrates my point.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function isOk() {&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;var notOk = false;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// do some logic&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;return !notOk;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So the boolean expressions I used involved variables, and I&#39;d somehow trained myself to code this way. This wasn&#39;t going to work in my project.&amp;nbsp;I didn&#39;t have or want variables to flip in all my functions. Nor was continuing to use keywords like &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt; and &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;. Lastly, I couldn&#39;t continue returning 1&#39;s and 0&#39;s, since they weren&#39;t actual booleans.&lt;br /&gt;
&lt;br /&gt;
Then I recalled that numbers are expressions - they&#39;re just missing an operator (or have an implied one, for you uber-geeks). When placing a &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Reference/Operators/Logical_Operators#Logical_NOT_%28!%29&quot;&gt;logical NOT operator&lt;/a&gt; before any variable (or, in this case, a number), &amp;nbsp;the result is a boolean value! Thus, with two characters, I can express the smallest boolean in JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;function doAndConfirm() {&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (doThing())&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return !0;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;else&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return !1;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
For some, there are performance implications to consider. I have not tested this, and frankly assume that a computer won&#39;t choke on such a minuscule&amp;nbsp;expressions. However, there is a real readability drawback. Plus, I do confuse sending the number 1 instead of &quot;!0&quot;.</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/7980603489540097162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/08/smallest-boolean-in-javascript.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7980603489540097162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7980603489540097162'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/08/smallest-boolean-in-javascript.html' title='The smallest boolean in JavaScript'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-6761856101444720136</id><published>2010-08-17T11:19:00.000-07:00</published><updated>2010-08-17T11:19:31.174-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="diary"/><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="proxy"/><title type='text'>Proxy - You&#39;ve come a long way, baby.</title><content type='html'>I began this post three weeks ago and should have published it then. For it has been an exciting three weeks, for me. I&#39;m proud to announce &lt;a href=&quot;http://github.com/bemson/Proxy/&quot;&gt;Proxy&lt;/a&gt;, my first opensource JavaScript project,&amp;nbsp;is available on &lt;a href=&quot;http://github.com/&quot;&gt;github.com&lt;/a&gt;.&amp;nbsp;Alas, this post is only about the journey to that destination...&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
One function (a constructor, to be precise), just under two-hundred lines of code, took one day to code and three weeks to document.&amp;nbsp;Finding my &quot;voice&quot; while documenting, proved the biggest hurdle.&amp;nbsp;I spent an entire weekend writing one paragraph - over and over and over. Of course, there was feature creep - yes, even for a single function. Plus my low self-esteem never failed to remind me of my imperfections, and convinced me delay my debut until otherwise.&lt;br /&gt;
&lt;br /&gt;
Sigh... I certainly broke myself, publishing this code. That &quot;sense of achievement&quot; everyone talks about? If you&#39;re like me, it requires overcoming an insidious &quot;sense of failure&quot; first. After so many years of writing code I&#39;ll never share, Proxy is the surest sign that I&#39;ve turned the corner, gained momentum, and hit the bottom... of my &lt;i&gt;excuse&lt;/i&gt; barrel, that is! (Ha, ha, ha!)&lt;br /&gt;
&lt;br /&gt;
Seriously, I noticed thought patterns that stopped me in my tracks, causing me to drag myself over procrastination every day. (They are still there). It might take a month or longer to document my next project, but knowing I finished this means I will finish the next.&amp;nbsp;With the utmost confidence, I can say that my wife, Stacy made all the difference. Our life together, and my vision for our future, have changed all my hopes and habits. &lt;b&gt;To Stacy: Thank you, and I love you.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
My apologies to those who thought this would be a technical post on Proxy. Or, to those who expected some insight about using &lt;a href=&quot;http://github.com/&quot;&gt;github.com&lt;/a&gt;. (You &lt;i&gt;were&lt;/i&gt; warned.) There is time for that, and I&#39;ll be sure to write on both subjects soon. For now, I&#39;m just glad to have something to share.</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/6761856101444720136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/08/proxy-youve-come-long-way-baby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6761856101444720136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6761856101444720136'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/08/proxy-youve-come-long-way-baby.html' title='Proxy - You&#39;ve come a long way, baby.'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-4621419413454658177</id><published>2010-07-30T09:00:00.000-07:00</published><updated>2010-07-30T09:00:01.531-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="js"/><title type='text'>Use JavaScript comment-urls instead of the traditional void(0) method</title><content type='html'>The longstanding compromise, between reducing inline JavaScript and preserving accessibility, has been to use &quot;javascript:void(0)&quot; in link hrefs and form-element actions. These elements and attributes are the hardened&amp;nbsp;fall-back to&amp;nbsp;&lt;a href=&quot;http://www.quirksmode.org/js/events_advanced.html&quot;&gt;DOM Level 2 events&lt;/a&gt;, and (unlike myself) many believe &lt;i&gt;something must be there.&lt;/i&gt;&amp;nbsp;Well the ubiquitous technique has a successor that is new to me. I&#39;m no more excited about it&#39;s purpose, but glad something new has come along.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Unlike most of what I post here, I did not learn this technique but rather observed it, while using &lt;a href=&quot;http://mint.com/&quot;&gt;Mint.com&lt;/a&gt;.&amp;nbsp;Instead of invoking the&amp;nbsp;method which&amp;nbsp;&lt;i&gt;returns&lt;/i&gt; nothing (actually, &lt;i&gt;void()&lt;/i&gt; returns &quot;undefined&quot;), they instead use JavaScript that &lt;i&gt;does&lt;/i&gt; nothing, with a single-line comment. These JavScript comment-urls work in all web browser, supporting JavaScript version 1.0.&lt;br /&gt;
&lt;br /&gt;
Wherever you use the JavaScript &lt;i&gt;void()&lt;/i&gt; method, like so:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;a href=&quot;javascript:void(0)&quot;&amp;gt;Do Something&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Simply use a JavaScript comment, like so:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;a href=&quot;javascript://&quot;&amp;gt;Do Something&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I prefer this approach because it&#39;s a shorter string - taking up less bandwidth, uses fewer threads/cycles, and is poetic in it&#39;s simplicity. If you want JavaScript to take over yet do nothing, I couldn&#39;t imagine anything less than a comment.&amp;nbsp;Again, I do not generally advocate JavaScript-urls, but feel if you must use them, use this one.&lt;br /&gt;
&lt;br /&gt;
Do share if you&#39;ve found a JavaScript capable web browser that does not support this technique. Or, let me know why you (too) think JavaScript-urls should not be employed... It&#39;s an opinion of mine (which I&#39;d like to avoid on this blog), but I might post about that later.</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/4621419413454658177/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/use-javascript-comment-urls-instead-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/4621419413454658177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/4621419413454658177'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/use-javascript-comment-urls-instead-of.html' title='Use JavaScript comment-urls instead of the traditional void(0) method'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-7269017394917794459</id><published>2010-07-26T10:31:00.000-07:00</published><updated>2010-07-26T11:06:26.918-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="money"/><category scheme="http://www.blogger.com/atom/ns#" term="smartypig"/><title type='text'>Saving to buy things</title><content type='html'>&lt;div&gt;Remember how your elders would tell you to save &lt;i&gt;in order to&lt;/i&gt;&amp;nbsp;save? As in, &quot;this money should never be spent&quot;? Reality check: that&#39;s hard to do. Sure, I save money (all I can); I even save&amp;nbsp;&lt;i&gt;to&lt;/i&gt; save it. But then I need (ok, &lt;i&gt;want&lt;/i&gt;) to buy something, and there goes my savings. That&#39;s normal, but the problem is I never spend my money on the reason I&#39;m saving my money.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;After discussing finances with my wife - an exciting topic for us both - I ventured online and discovered&amp;nbsp;&lt;a href=&quot;http://www.smartypig.com/&quot;&gt;SmartyPig.com&lt;/a&gt;. It&#39;s a dream service for penny pinchers, like myself. The site facilitates saving towards financial&amp;nbsp;goals, and provides the literal and proverbial &quot;bucket&quot; to separate your monies.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now, I already use &lt;a href=&quot;http://www.mint.com/&quot;&gt;Mint.com&lt;/a&gt; - a financial management service that is entirely useful towards monitoring my spending across various accounts. (Thanks Malaney!) It also offers goal oriented savings, and will track your progress like SmartyPig. The difference is SmartyPig actually gives you an account, a temporary one, to fund your goal. If Mint had this ability (they suggest regular third-party savings accounts), I wouldn&#39;t use SmartyPig; but Mint only &lt;i&gt;tracks&lt;/i&gt; money.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;On top of giving you a bucket to put your money in, SmartyPig rewards long time planners with APY of 2.15%. My wife and I are saving for a home - which takes some time to fund - and that kind of benefit really appeals to me. Plus, I don&#39;t have to leave my favorite bank to do it. The fact that my money comes back to my account, means I&#39;m not in bed with SmartyPig longer than I like.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This is not a tutorial on using SmartyPig (the are &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;safe=off&amp;amp;q=tutorial+on+using+smartypig&amp;amp;aq=f&amp;amp;aqi=&amp;amp;aql=&amp;amp;oq=&amp;amp;gs_rfai=&quot;&gt;plenty of tutorials online&lt;/a&gt;), just a hearty applause to the digital age. I learned that my money doesn&#39;t have to be tied down to a bank or risked in a nervous stock market. Today, I can shop for the things I want and not harm mine or my wife&#39;s future finances. Good and finally!&lt;br /&gt;
&lt;br /&gt;
Ah hem, lest I forget... &lt;b&gt;SmartyPig also lets you receive public contributions.&lt;/b&gt; See the bottom of my sidebar, if you&#39;d like to try &lt;i&gt;that&lt;/i&gt; out! (wink) Many, many thanks in advance!!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/7269017394917794459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/saving-to-buy-things.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7269017394917794459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/7269017394917794459'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/saving-to-buy-things.html' title='Saving to buy things'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-1858078892855297974</id><published>2010-07-23T09:00:00.000-07:00</published><updated>2010-07-23T09:00:05.470-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ie"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><title type='text'>Inferring node placement via special sourceIndex values</title><content type='html'>&lt;div&gt;I needed to know whether a node was &lt;i&gt;in&lt;/i&gt; the DOM. Figuring there was a native property or method towards this end, I scoured Mozilla&#39;s documentation but could find nothing. Then Microsoft (yes,&amp;nbsp;&lt;i&gt;them&lt;/i&gt;) offered hope with Internet Explorer&#39;s &lt;a href=&quot;http://help.dottoro.com/ljbxdemp.php&quot;&gt;sourceIndex&lt;/a&gt; property:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Retrieves the ordinal position of the object, in source order, as the object appears in the document&#39;s &lt;/i&gt;&lt;i&gt;all &lt;/i&gt;&lt;i&gt;collection.&lt;/i&gt;&lt;br /&gt;
&lt;div&gt;&lt;div style=&quot;text-align: right;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms534635(VS.85).aspx&quot;&gt;sourceIndex (MSDN)&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Put simply, this proprietary property holds the numeric index of a node within the &quot;all collection&quot; - an IE construct reflecting everything in the browser DOM. Thus, I wondered what the index would be for nodes in memory; that is, a&amp;nbsp;node not yet - or previously - appended to the DOM.&lt;br /&gt;
&lt;br /&gt;
A quick test proved the &lt;i&gt;sourceIndex&lt;/i&gt; property has special values for each scenario:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;A value of -1 means the node has never been placed in the DOM.&lt;/li&gt;
&lt;li&gt;A value of 0 means the node has been removed from the DOM.&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;*&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;*&amp;nbsp;&lt;/span&gt;&lt;/b&gt;While the first case is pretty straight forward, the second (when 0) has an implied caveat. All array-like constructs are zero-based, and there is always a node at the zeroth index of&amp;nbsp;&lt;i&gt;document.all&lt;/i&gt;. Therefore, unless you know more about your node, a &lt;i&gt;sourceIndex&lt;/i&gt;&amp;nbsp;of 0&amp;nbsp;could be a false-positive and the node may still be in the DOM.&lt;br /&gt;
&lt;br /&gt;
The generous folks at &lt;a href=&quot;http://help.dottoro.com/&quot;&gt;http://help.dottoro.com&lt;/a&gt;&amp;nbsp;added my findings to their &lt;i&gt;sourceIndex&lt;/i&gt;&amp;nbsp;reference. Given their due diligence, I feel they&#39;ve verified the application of my discovery.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I don&#39;t feel this proprietary property was intended as a node-placement indicator - hence the title of this blog entry. However, I&#39;ve used it to great success as one, in a project where an IE only solution was needed (rare, I know).&lt;br /&gt;
&lt;br /&gt;
Finally, for those interested in a cross browser solution, search stackoverflow.com to &lt;a href=&quot;http://stackoverflow.com/search?q=determine+when+a+node+is+in+the+DOM&quot;&gt;determine when a node is in the DOM&lt;/a&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/1858078892855297974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/inferring-node-placement-via-special.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/1858078892855297974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/1858078892855297974'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/inferring-node-placement-via-special.html' title='Inferring node placement via special sourceIndex values'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-2722820637952783844</id><published>2010-07-19T16:11:00.000-07:00</published><updated>2010-07-20T09:44:33.554-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="demo"/><category scheme="http://www.blogger.com/atom/ns#" term="events"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="w3c"/><title type='text'>w3c browsers fire bubble listeners before capture listeners</title><content type='html'>In w3c browsers, the event object&#39;s &lt;a href=&quot;http://help.dottoro.com/ljjeesba.php&quot;&gt;eventPhase&lt;/a&gt;&amp;nbsp;property may indicate when it is in &lt;i&gt;capture&lt;/i&gt; or &lt;i&gt;bubble&lt;/i&gt; mode with a 1 or 3, respectively. A value of 2 indicates that the event object is &quot;at&quot; or processing the target node. However, when the &lt;i&gt;eventPhase&lt;/i&gt;&amp;nbsp;is 2, the event&#39;s mode is fuzzy.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
I discovered this while seeking to branch a handler function&#39;s execution based on the mode. My handler not only had trouble distinguishing the mode for the target node, the &lt;i&gt;eventPhase&lt;/i&gt;&amp;nbsp;was actually 2 twice.&amp;nbsp;Once at the end of an event&#39;s capture mode, and again at the start of it&#39;s bubble mode (since both end and begin at the target node).&amp;nbsp;It seems that modern browsers are equally confused.&lt;br /&gt;
&lt;br /&gt;
More often than not, w3c browsers will trigger bubble listeners before capture listeners for the target node - as if the browser too can not distinguish the mode.&amp;nbsp;You can preview this odd behavior in a demo at&amp;nbsp;&lt;a href=&quot;http://jsbin.com/adena3/2&quot;&gt;http://jsbin.com/adena3/2&lt;/a&gt;/. As usual, do share your results for your browser(s), as a comment to this blog entry. So far, though nowhere near consistent, Firefox performs as expected for a few form elements.&lt;br /&gt;
&lt;br /&gt;
I doubt this is a bug, but rather it is by design. After all, there &lt;i&gt;are&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal;&quot;&gt; only&lt;/span&gt;&lt;/i&gt; three phases. To explicitly signal an event&#39;s mode and location, as it traverses the DOM, requires four values. Plus, no document requires that browsers execute listeners in the order they were assigned... The problem is that historically, w3c browsers have done a pretty good job of executing listeners in the order they were assigned.&lt;br /&gt;
&lt;br /&gt;
Still, even as a bug, it&#39;s one most developers will not encounter. Observing best practices (like event delegation), and considering common interface requirements, few will ever assign a capture listener to a target node. As well, listener order matters less on the target node, since the event is neither capturing nor bubbling at that moment, and thus all listeners would execute. Technically, w3c browsers are not behaving badly.&lt;br /&gt;
&lt;br /&gt;
Thus, my issue is with the&amp;nbsp;&lt;a href=&quot;http://help.dottoro.com/ljeuqqoq.php&quot;&gt;addEventListener()&amp;nbsp;&lt;/a&gt;method. It&#39;s &quot;capture&quot; parameter implies that a given function will execute in one of two modes (&lt;i&gt;capture&lt;/i&gt; or &lt;i&gt;bubble&lt;/i&gt;), and capture listeners execute &lt;b&gt;before&lt;/b&gt; bubble listeners. I fear, when it comes to the target node, passing any &lt;i&gt;capture&lt;/i&gt;&amp;nbsp;value to this method, equates to &quot;either&quot;.</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/2722820637952783844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/w3c-browsers-fire-bubble-listeners.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/2722820637952783844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/2722820637952783844'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/w3c-browsers-fire-bubble-listeners.html' title='w3c browsers fire bubble listeners before capture listeners'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-8310885602605244860</id><published>2010-07-14T20:56:00.000-07:00</published><updated>2010-07-14T21:24:06.879-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="demo"/><category scheme="http://www.blogger.com/atom/ns#" term="events"/><category scheme="http://www.blogger.com/atom/ns#" term="ie"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><title type='text'>Internet Explorer doesn&#39;t bubble click events to the window</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;This is a simple one. I put some sample code on &lt;/span&gt;&lt;a href=&quot;http://jsbin.com/ijuta3&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;jsbin.com&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;to&amp;nbsp;show how IE doesn&#39;t bubble click events to the window, while w3c browsers do. This is important, because I would normally think &lt;/span&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;to&lt;/span&gt;&lt;/i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt; use the window as a &quot;global event listener&quot;, not the document. Yeah, I learned this one the hard way.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Learning about which browser events bubble to which top level object is critical to my current project. Expect more posts about which events bubble/capture from/to what node/object... Wow, I just wrote put three sentences into one.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Help my research (or research for others) and share your results on various browsers. Just open the demo, click around a bit, and let me know if the click event hit the browser or not. Or, revise my code to test other events and share those results.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Many thanks!&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/8310885602605244860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/internet-explorer-doesnt-bubble-click.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/8310885602605244860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/8310885602605244860'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/internet-explorer-doesnt-bubble-click.html' title='Internet Explorer doesn&#39;t bubble click events to the window'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-6099359083773884183</id><published>2010-07-14T11:03:00.000-07:00</published><updated>2010-08-17T15:31:33.813-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="debug"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="tips"/><title type='text'>Debug easier by naming your closures</title><content type='html'>&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;I was profiling some code when I noticed that several routines were listed as &quot;(?)()&quot; in&amp;nbsp;&lt;a href=&quot;http://getfirebug.com/&quot;&gt;Firebug&lt;/a&gt;,&amp;nbsp;and&amp;nbsp;&quot;JScript anonymous function&quot; in&amp;nbsp;&lt;a href=&quot;http://www.microsoft.com/express/windows/&quot;&gt;MS&#39;s Visual Studio&lt;/a&gt;. This proved frustrating, as recognizing my closures were critical to evaluating my code - I couldn&#39;t tell which were performing well, let alone executing.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;It was burdensome, but I named all the anonymous functions. Hopefully today&#39;s JavaScript optimizers and minimizers know enough to remove such useless text (otherwise, I&#39;ll have to), but it sure helped my debugging effort.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;So, if your code has lines like these:&lt;/div&gt;&lt;blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;obj.critical = function () {};&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;useCriticalFunc(function () {});&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;You might try naming the anonymous functions, like so:&lt;/div&gt;&lt;blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;obj.critical = function criticalMethod() {};&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;useCriticalFunc(function criticalFunc() {});&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Now, you should be able to recognize the closures, in your debugger of choice!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/6099359083773884183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/debug-easier-by-naming-your-closures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6099359083773884183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/6099359083773884183'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/debug-easier-by-naming-your-closures.html' title='Debug easier by naming your closures'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-749857840534628149</id><published>2010-07-14T09:46:00.000-07:00</published><updated>2010-07-14T12:52:14.990-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="events"/><category scheme="http://www.blogger.com/atom/ns#" term="ie"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><title type='text'>Internet Explorer sanitizes events between nodes</title><content type='html'>&lt;b&gt;Events are hard in IE. &lt;/b&gt;That is just a fact.&lt;br /&gt;
&lt;br /&gt;
I&#39;m not here to gripe about how IE&#39;s event object doesn&#39;t adhere to standards, nor offers alternatives. Really, I&#39;m not. This is actually a surprising discovery that has less to do with the standard IE/MS diatribe, and more to do with a unique aspect of their event object.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Of all it&#39;s properties, the IE event object allows you to edit two: &lt;a href=&quot;http://help.dottoro.com/ljpbqcqb.php&quot;&gt;returnValue &lt;/a&gt;and &lt;a href=&quot;http://help.dottoro.com/ljsgdvke.php&quot;&gt;cancelBubble&lt;/a&gt;. The &lt;i&gt;returnValue &lt;/i&gt;property may be set to anything, while &lt;i&gt;cancelBubble &lt;/i&gt;is converted to the boolean equivalent of whatever you assign.&lt;br /&gt;
&lt;br /&gt;
You may add arbitrary properties to the event object, via a handler function. (As with w3c browsers, be careful not to cause an exception by writing to a read-only property.) However, you may not prototype the event&#39;s constructor in IE (it doesn&#39;t have one). Nor does IE implement the ever-popular &lt;a href=&quot;http://help.dottoro.com/ljufnnvc.php&quot;&gt;hasOwnProperty() &lt;/a&gt;method. (Why? That&#39;s another post, let alone blog.)&lt;br /&gt;
&lt;br /&gt;
Now after mangling an event object sufficiently (and within the aforementioned limits), how should that object look when it bubbles to the next node in the DOM? Unfortunately, with IE, it will be the same way it began in the previous one. Only the &lt;i&gt;returnValue &lt;/i&gt;will retain the previously assigned value. (So would the &lt;i&gt;cancelBubble &lt;/i&gt;property, but that doesn&#39;t matter since it wouldn&#39;t reach the next node anyway.) This behavior is observed in IE 6 thru 8.&lt;br /&gt;
&lt;br /&gt;
IE either sanitizes the event object between nodes, or provides a new one altogether. There is no way I can tell which from looking at the object, alone. But recalling that, causes me to gripe about how the object doesn&#39;t have a standard &lt;a href=&quot;http://help.dottoro.com/ljmhtrht.php&quot;&gt;timestamp&lt;/a&gt; property, or an equivalent native means to uniquely identify one event object from the next...&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Mind you, this does not mean handler functions cannot pass arbitrary properties amongst themselves. The &quot;sanitization&quot; IE does is between nodes (or what an event bubbles through), not the numerous handler functions listening to one.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;I might post a demo for this, but it&#39;s a tad complicated to prove a negative. Anyway, I discovered this while coding recently, and it blew chunks. Hope my experience helps!</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/749857840534628149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/internet-explorer-events-are-sanitized.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/749857840534628149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/749857840534628149'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/internet-explorer-events-are-sanitized.html' title='Internet Explorer sanitizes events between nodes'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1482295281150166231.post-1599445854612363394</id><published>2010-07-14T08:05:00.000-07:00</published><updated>2010-07-14T11:21:56.679-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="brief"/><title type='text'>Try, try again</title><content type='html'>I&#39;ve failed miserably at blogging before. Blogging had been a confronting exercise, where I had to impress my readers with coherent arguments and razor sharp wit. Perhaps that has always been the problem, in all my writings. There was a time, when I would take hours to write an email. It had all the burden of a delicate surgery - the patient being a relationship.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This time, I plan to write short posts. Indeed, twitter may be the proper forum for my thoughts. I aspire to more, however, I&#39;m alright with doing less. Even now, while at work, I don&#39;t have time to write this post. But I need to begin somewhere.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I&#39;ll blog about what I&#39;ve learned. What sparked this diary-style blog is my current work, in coding JavaScript. I realized that all the places I look to understand how to code well, were also blogs (of a sort). I&#39;d learned things while coding. Why not start a blog of my own?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I do seek fame and recognition - one hopes fortune will follow either. Above all, I want to use what I&#39;ve learned in future endeavors. Yesterday, I ran into a roadblock because I presumed something about my work, and never wrote it down. That bit me in the arse - ruined the days outlook, in fact.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I&#39;ll post on other learnings, which is why coding isn&#39;t explicitly in the title. Right now, I&#39;ve on a mission to be achieve my goals and earn what I deserve. I am writing to you, but for myself. Hope we enjoy the ride! &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnings-bemson.blogspot.com/feeds/1599445854612363394/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/try-try-again.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/1599445854612363394'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1482295281150166231/posts/default/1599445854612363394'/><link rel='alternate' type='text/html' href='http://learnings-bemson.blogspot.com/2010/07/try-try-again.html' title='Try, try again'/><author><name>Bemson</name><uri>http://www.blogger.com/profile/09030646041433638139</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ0_ZomPYgKU2Eb6TSyC8WWVVZHS_ynH5oeyxv3GS10goatepGR_8s8Bewnb2TYGEcGXoJ7f-ZOoPsOscmCZ4qSB9Q8N-kc5pZwVCr7aidP-4acjz5_PKVZViSqdEbCSE/s220/lightbulb.jpg'/></author><thr:total>1</thr:total></entry></feed>