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

<channel>
	<title>Mark Caudill</title>
	<atom:link href="http://markcaudill.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://markcaudill.com</link>
	<description>All about me</description>
	<pubDate>Fri, 06 Apr 2012 15:57:13 +0000</pubDate>
	
	<language>en</language>
			<item>
		<title>JavaScript New Features (EcmaScript 5)</title>
		<link>http://markcaudill.com/2009/04/javascript-new-features-ecma5/</link>
		<comments>http://markcaudill.com/2009/04/javascript-new-features-ecma5/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 18:51:44 +0000</pubDate>
		<dc:creator>Mark Caudill</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[ecmascript]]></category>

		<guid isPermaLink="false">http://markcaudill.com/?p=6</guid>
		<description><![CDATA[Like any good programmer, I&#8217;d like to stay on top of any changes planned for programming languages that I use (or scripting languages).  So when I heard about EcmaScript 5th Edition (near final draft) being released, I wanted to get all of the juicy details on what to expect.  As it turns out, this hasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Like any good programmer, I&#8217;d like to stay on top of any changes planned for programming languages that I use (or scripting languages).  So when I heard about <a href="http://www.ecma-international.org/news/PressReleases/PR_Ecma_finalises_major_revision_of_ECMAScript.htm" target="_blank">EcmaScript</a> <a href="http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf" target="_blank">5th Edition</a> (near final draft) being released, I wanted to get all of the juicy details on what to expect.  As it turns out, this hasn&#8217;t been documented really well yet: so I did the better thing and read <a href="http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf" target="_blank">the draft</a>.</p>
<p>There are some really exciting things to come, some of the biggest being to the foundation Object object&#8217;s functions which will allow turning off Enumeration on properties, making &#8220;read only&#8221; properties, etc.  I&#8217;ve noticed a lot of this has come from Mozilla&#8217;s innovation and also I see some similarities to <a href="http://prototypejs.org/?markcaudill" target="_blank">PrototypeJS</a>&#8217;s modifications to prototypes.</p>
<ul>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#JSON">JSON object</a></li>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#Object">Object object</a></li>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#Function">Function object</a></li>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#Array">Array object</a></li>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#other">String, Number, Boolean, Date</a></li>
<li><a href="http://markcaudill.com/index.php/2009/04/javascript-new-features-ecma5/#misc">Miscellaneous</a></li>
</ul>
<p><span id="more-6"></span></p>
<h2><a name="JSON" href="#JSON">JSON object</a></h2>
<p>The first major addition in the draft is the JSON object, which is not a constructor but rather similar to the Math object and some of Object&#8217;s functionality.  JSON.parse takes a JSON string and creates an object.  JSON.stringify takes an object and creates a string.  Pretty simple!<br />
JSON.parse has an optional 2nd parameter (a function) that receives a key and value which it can return a value to override the original value.<br />
JSON.stringify has an optional 2nd and 3rd parameter. The second being a function to modify the way objects and arrays are stringified or an array of white listed keys to stringify.  The third being a string or number that allows the result to have a singular space or up to 100 spaces (and line feeds) between keys of the object.</p>
<h2><a name="Object" href="#Object">Object object</a></h2>
<ul>
<li>Object.getPrototypeOf(O) returns the prototype of O if O is an Object.</li>
<li>Object.getOwnPropertyDescriptor(O, P) returns the property descriptor of O&#8217;s (as object) property P (as property of O).</li>
<li>Object.getOwnPropertyNames(O) returns an array of property names (uses ToString on the names).</li>
<li>Object.create(O[, Properties]) returns an object with a prototype of O and properties according to Properties (as if called through Object.defineProperties).</li>
<li>Object.defineProperty(O, P, Attributes) returns O after adding a new property P with a property descriptor of Attributes.  Just imagine the possibilities when O is a DOM element :). Read: DOM Prototypes <a href="http://msdn.microsoft.com/en-us/library/dd282900(VS.85).aspx" target="_blank">Part 1 (Intro)</a>, <a href="http://msdn.microsoft.com/en-us/library/dd229916(VS.85).aspx" target="_blank">Part 2</a></li>
<li>Object.defineProperties(O, Properties) returns O after enumerating Properties as name/descriptor (e.g. {name: descriptor}).</li>
<li>Object.seal(O) returns O after setting the internal Configurable flag to false for each property of O and the internal Extensible property of O to false.</li>
<li>Object.freeze(O) returns O similar to seal except the internal Writable flag is also set to false.</li>
<li>Object.preventExtensions(O) returns O after setting the internal Extensible property of O to false.</li>
<li>Object.isSealed(O) returns boolean based on all properties&#8217; Configurable (any true returns false) and O&#8217;s internal Extensible property (a false returns true).</li>
<li>Object.isFrozen(O) returns boolean similarly to isSealed except Writable is checked (any true return false).</li>
<li>Object.isExtensible(O) returns boolean value of the internal Extensible property of O.</li>
<li>Object.keys(O) returns an array of property names.</li>
</ul>
<h2><a name="Function" href="#Function">Function object</a></h2>
<p>Function binding!  Now <em>this</em> is based on whatever you bind a function to or whatever <em>this</em> internally would be by default.  What that means for us is that we can bind functions easily to objects via the prototype so that calling <em>this</em> in those functions returns the associated object. Function.prototype.bind(this[[, arg1] arguments&#8230;]) where arg1/arguments are passed into the function first.</p>
<p>See: <a href="http://prototypejs.org/api/function/bind" target="_blank">PrototypeJS&#8217; implementation</a></p>
<h2><a name="Array" href="#Array">Array object</a></h2>
<p>Array.isArray(arg) returns boolean based on if the internal Class property is &#8220;Array&#8221;.</p>
<ul>
<li>Array.prototype.indexOf(needle[, fromIndex]) returns the position of needle in the array, if not return -1 is returned.  If fromIndex is positive or 0 (defaults to 0) this is the start index; if it is negative fromIndex is the offset from the end of the array to begin searching.</li>
<li>Array.prototype.lastIndexOf(needle[, fromIndex]) returns similarly to indexOf except the array is searched reversely.</li>
<li>Array.prototype.every(callFunc[, thisArg]) returns boolean depending on callFunc&#8217;s return value via iterating the array.  If thisArg is specified, the function is bound to thisArg, otherwise thisArg defaults to undefined.  callFunc gets three arguments for each element in the array: value, count, the object of <em>this</em> (not what <em>thisArg</em> is!).</li>
<li>Array.prototype.some(callFunc[, thisArg]) returns boolean similarly to every except one true instance returns true.</li>
<li>Array.prototype.forEach(callFunc[, thisArg]) returns nothing, but processes similarly to some and every.</li>
<li>Array.prototype.map(callFunc[, thisArg]) returns a new array of return values by processing similarly to forEach.</li>
<li>Array.prototype.filter(callFunc[, thisArg]) returns a new array of elements that callFunc returns true while processing (similarly to the processing of forEach).</li>
<li>Array.prototype.reduce(callFunc[, initialValue]) returns a value that is daisy-chained through callFunc by passing accumulator, property value, index, and the object.  The return value of callFunc is passed into the next call as accumulator, then accumulator is returned.  initialValue sets the starting accumulator, otherwise this starts at index 1 (2nd element) with an accumulator of index 0.</li>
<li>Array.prototype.reduceRight(callFunc[, initialValue]) returns similarly to reduce except from right-to-left in the array (last to first).</li>
</ul>
<h2><a name="other" href="#other">String, Number, Boolean, Date</a></h2>
<p>Date.now() returns a Number with a unix timestamp.</p>
<ul>
<li>String.prototype.trim() returns the value of this without white space on the left or right.</li>
<li>Date.prototype.toISOString() returns a string representing the time in the Date Time string format as UTC.</li>
<li>String.prototype.toJSON(key), Boolean.prototype.toJSON(key), Number.prototype.toJSON(key), Date.prototype.toJSON(key) returns a string that represents object.  Does anyone have some ideas on what key actually does for this?</li>
</ul>
<h2><a name="misc" href="#misc">Miscellaneous</a></h2>
<p>Of importance is that Unicode 3.0 is now supported, including relevant whitespace additions.</p>
<p>Line terminator characters proceeded by an escape sequence (\) are allowed in a string.</p>
<p>Indirect calls to eval use the global (window) environment.</p>
<p>For-in doesn&#8217;t throw errors for null/undefined, instead it just continues as if it was given an object that had no enumerable properties.</p>
<p>Strict Mode was added, but I&#8217;m unsure if we&#8217;ll see this in JavaScript (see Annex C; page 237).</p>
<p>New keyword debugger is moved from future reserved words to keywords and allows triggering a breakpoint when running within a debugger, otherwise it should have no observable effect.</p>
<p>The Object object is now setup drastically different internally: ReadOnly becomes &#8220;Writable&#8221;, DontEnum becomes &#8220;Enumerable&#8221;, DontDelete becomes &#8220;Configurable&#8221; (also only allow some changes; with exceptions, see 8.6.1).  &#8220;Set&#8221; was also changed from Put and is by default an undefined function.  Most of this can be written over using property descriptors (see Object.defineProperty above).</p>
<p>(A lot more miscellaneous stuff, see Annex E for upgrade breakers.)</p>
<h2>Suggestions? Comments?</h2>
<p>Thank you ECMA :).  Hope to see all of this implemented in a year or two (since IE8 in standards mode and Firefox 3.1 are to support at least portions of this) as part of JavaScript.  Is there anything else you think should be in this post?  Comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://markcaudill.com/2009/04/javascript-new-features-ecma5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript closures</title>
		<link>http://markcaudill.com/2009/03/javascript-closures/</link>
		<comments>http://markcaudill.com/2009/03/javascript-closures/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 04:01:30 +0000</pubDate>
		<dc:creator>Mark Caudill</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[circular reference]]></category>

		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://markcaudill.com/?p=5</guid>
		<description><![CDATA[There isn&#8217;t a huge conspiracy to hide what closures mean to the power of JavaScript, but the principles can be easily understood.
A closure is actually more liberating than the name implies.  It opens the door to new possibilities by passing variables between lower-level functions.
Take for example, a very simple closure:

var ourFunction = function&#40;&#41; &#123;
var ourFunction2 [...]]]></description>
			<content:encoded><![CDATA[<p>There isn&#8217;t a huge conspiracy to hide what closures mean to the power of JavaScript, but the principles can be easily understood.</p>
<p>A closure is actually more liberating than the name implies.  It opens the door to new possibilities by passing variables between lower-level functions.</p>
<p>Take for example, a very simple closure:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="kw2">var</span> ourFunction = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> ourFunction2 = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> alert<span class="br0">&#40;</span>ourVar<span class="br0">&#41;</span>; <span class="br0">&#125;</span>;<br />
<span class="kw2">var</span> ourVar = <span class="st0">&quot;A simple JavaScript closure.&quot;</span>;</p>
<p>ourFunction2<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span>;</div>
</div>
<p>As you can see, the ourVar variable is available to ourFunction2 despite ourVar being defined in the scope of ourFunction (locally).  Even if ourFunction2 wasn&#8217;t defined inside of ourFunction, we&#8217;d still have access to ourVar.  Similarly, if ourVar was a parameter of ourFunction, we&#8217;d still have access to it within ourFunction2.<br />
<span id="more-5"></span></p>
<h2>Internet Explorer and Circular References</h2>
<p>So what is it about closures that give them a bad rap?  The horrible truth is that Internet Explorer is to blame.  A bug in their automatic garbage collection of closures (removing unneeded closures) causes circular references involving DOM nodes or ActiveX objects to not be freed from the memory until the browser closes.  A circular reference is created when 2 or more functions/elements/objects refer back to each other.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">document.onload = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> obj = document.getElementById<span class="br0">&#40;</span><span class="st0">&quot;someDiv&quot;</span><span class="br0">&#41;</span>;<br />
obj.onclick = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> alert<span class="br0">&#40;</span><span class="st0">&quot;Leak&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span>;<br />
<span class="br0">&#125;</span>;</div>
</div>
<p>The <em>obj</em> variable is referenced, and then a closure is created for the onclick event of <em>obj</em>.  This means that the closure will never be cleared, even if document.onload is changed.  But there is hope!  One solution is to simply set <em>obj</em> to null after creating the closure.  This breaks the circular reference by removing one of the objects in that circular reference.</p>
<p>Another solution is to create another closure within the function to prevent the circular reference.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">document.onload = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> obj = document.getElementById<span class="br0">&#40;</span><span class="st0">&quot;someDiv&quot;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> obj.onclick = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> alert<span class="br0">&#40;</span><span class="st0">&quot;Leak&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span>; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span>;</div>
</div>
<p>Or, alternatively, just avoid creating a closure in general.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">document.onload = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> obj = document.getElementById<span class="br0">&#40;</span><span class="st0">&quot;someDiv&quot;</span><span class="br0">&#41;</span>;<br />
obj.onclick = respondFunc;<br />
<span class="br0">&#125;</span>;<br />
<span class="kw2">var</span> respondFunc = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> alert<span class="br0">&#40;</span><span class="st0">&quot;No leak&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span>;</div>
</div>
<h2>To closure or not to closure?</h2>
<p>Any way you look at it, closures are a powerful feature of JavaScript.  They enable some really special things to happen in JavaScript that would be much more difficult without the feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://markcaudill.com/2009/03/javascript-closures/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UI Optimization</title>
		<link>http://markcaudill.com/2008/04/ui-optimization/</link>
		<comments>http://markcaudill.com/2008/04/ui-optimization/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 01:07:09 +0000</pubDate>
		<dc:creator>Mark Caudill</dc:creator>
		
		<category><![CDATA[Web Trends]]></category>

		<guid isPermaLink="false">http://markcaudill.com/?p=4</guid>
		<description><![CDATA[If you visit half of the top 100 sites on Alexa, you&#8217;ll notice a growing trend among “Web2.0” sites.  Besides the use of JavaScript with fall back support, you&#8217;ll see designs that utilize clean designs that are optimized for the end-user.
This growing trend, which in my opinion is great, seems to have come out [...]]]></description>
			<content:encoded><![CDATA[<p>If you visit half of the top 100 sites on Alexa, you&#8217;ll notice a growing trend among “Web2.0” sites.  Besides the use of JavaScript with fall back support, you&#8217;ll see designs that utilize clean designs that are optimized for the end-user.</p>
<p>This growing trend, which in my opinion is great, seems to have come out of the simple concept: Keep It Simple Stupid. With sites like MSN and NBC, a user can easily get lost in finding what they&#8217;re looking for if it&#8217;s their first time visiting the site — think of your grandma that just got that brand new Intel Quad Core.  They go in looking for show times and end up writing a chain letter about boycotting XYZ Corp.</p>
<p>Some of the biggest design sites out there (e.g. Smashing Magazine) award and applaud sites that adhere to standards, and many of their reward winners are professionally simple sites.  Taste isn&#8217;t always more graphics.</p>
]]></content:encoded>
			<wfw:commentRss>http://markcaudill.com/2008/04/ui-optimization/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

