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

<channel>
	<title>Garkbit Blog &#187; Mootools</title>
	<atom:link href="http://wp.garkbit.com/tag/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.garkbit.com</link>
	<description>... on the other side of the universe</description>
	<lastBuildDate>Mon, 14 Dec 2009 13:29:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript for&#8230;in</title>
		<link>http://wp.garkbit.com/2009-09-13/javascript-for-in/</link>
		<comments>http://wp.garkbit.com/2009-09-13/javascript-for-in/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 13:30:00 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[ASP.NET/C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://wp.garkbit.com/?p=106</guid>
		<description><![CDATA[A couple of weeks ago a college of mine got a JavaScript error at one of our SharePoint sites. It turn out, someone at Microsoft has used a for&#8230;in loop to iterate over an Array. This works fine as long as you don&#8217;t modify the Array object. So when used with Mootools, that adds properties [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago a college of mine got a JavaScript error at one of our SharePoint sites. It turn out, someone at Microsoft has used a for&#8230;in loop to iterate over an Array. This works fine as long as you don&#8217;t modify the Array object. So when used with Mootools, that adds properties and methods to the Array object, the SharePoint script gets the hick-ups and dies.</p>
<p>The JavaScript documentation states:</p>
<blockquote><p>Iterates a specified variable over all the properties of an object, in arbitrary order. For each distinct property, the specified statement is executed.</p></blockquote>
<p>&#8230; and</p>
<blockquote><p>Although it may be tempting to use this as a way to iterate over Array elements, because the for&#8230;in statement iterates over user-defined properties in addition to the array elements, if you modify the Array object, such as adding custom properties or methods, the for&#8230;in statement will return the name of your user-defined properties in addition to the numeric indexes. Thus it is better to use a traditional for loop with a numeric index when iterating over arrays.</p></blockquote>
<p>I made a simple example to show the difference between iterating over Arrays and Objects. This is with Mootols included on the page.</p>
<p><strong>JavaScript</strong></p>
<pre class="brush: jscript;">
console.log('===== Array Example ===== ');

// Array
var a = ['alpha', 'bravo', 'charlie'];
console.log('Creating a new Array:', a);
console.log('The array length is:', a.length);

// For
console.log('--- Start For --- ');
for (var i = 0, j = a.length; i &lt; j; i++) {
    console.log(i, ':', a[i]);
}
console.log('--- End For --- ');

// For-in
console.log('--- Start For-in --- ');
for (var ii in a) {
    console.log(ii, ':', a[ii]);
}
console.log('--- End For-in --- ');
</pre>
<p><strong>Output</strong></p>
<pre class="brush: plain;">
===== Array Example =====
Creating a new Array: [&quot;alpha&quot;, &quot;bravo&quot;, &quot;charlie&quot;]
The array length is: 3
--- Start For ---
0 : alpha
1 : bravo
2 : charlie
--- End For ---
--- Start For-in ---
0 : alpha
1 : bravo
2 : charlie
$family : Object name=array
each : forEach()
clean : function()
associate : function()
link : function()
contains : function()
extend : function()
getLast : function()
getRandom : function()
include : function()
combine : function()
erase : function()
empty : function()
flatten : function()
hexToRgb : function()
rgbToHex : function()
toJSON : function()
--- End For-in ---
</pre>
<p>And here using an object.<br />
<strong></strong></p>
<p><strong>JavaScript</strong></p>
<pre class="brush: jscript;">
console.log('===== Object Example =====');

// Object
var o = { 'one': 'alpha', 'Bravo': 'bravo', 'three': 'charlie' };
console.log('Creating a new Array:', o);

// For-in
console.log('--- Start For-in --- ');
for (var item in o) {
    console.log(item, ':', o[item]);
}
console.log('--- End For-in --- ');
</pre>
<p><strong>Output</strong></p>
<pre class="brush: plain;">
===== Object Example =====
Creating a new Array: Object one=alpha Bravo=bravo three=charlie
--- Start For-in ---
one : alpha
Bravo : bravo
three : charlie
--- End For-in ---
</pre>
<p>Read more about the for&#8230;in operation at MDC Core JavaScript 1.5 Guide: <a title="MDC Core JavaScript 1.5 Guide: Object Manipulation" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Object_Manipulation_Statements">Object Manipulation</a>.</p>
<p>Unfortunately this stupid mistake prevents us from using Mootools on this site. And we might have to reconsider the use of Mootols on more sites in the future — AND THAT SUCKS!</p>
]]></content:encoded>
			<wfw:commentRss>http://wp.garkbit.com/2009-09-13/javascript-for-in/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Keetology&#8217;s Mootools articles</title>
		<link>http://wp.garkbit.com/2009-07-21/keetologys-mootools-articles/</link>
		<comments>http://wp.garkbit.com/2009-07-21/keetologys-mootools-articles/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 10:21:57 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Keetology]]></category>

		<guid isPermaLink="false">http://wp.garkbit.com/?p=91</guid>
		<description><![CDATA[Mark Obcena has started writing a series of Mootools articles for the intermediate Mootooler  at he&#8217;s blog Keetology. So far he has posted two really, really good articles. Check them out!
The DOM Fetcher Functions
Natives, Generics and Extending the Language
]]></description>
			<content:encoded><![CDATA[<p>Mark Obcena has started writing a series of Mootools articles for the intermediate Mootooler  at he&#8217;s blog <a title="Keetology" href="http://keetology.com/blog/">Keetology</a>. So far he has posted two really, really good articles. Check them out!<br />
<a title="Up The Herd: Playing Fetch" href="http://keetology.com/blog/2009/07/01-up-the-moo-herd-i-playing-fetch">The DOM Fetcher Functions</a><br />
<a title="Up The Herd 2: Native Flora and Fauna" href="http://keetology.com/blog/2009/07/20/up-the-herd-ii-native-flora-and-fauna">Natives, Generics and Extending the Language</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wp.garkbit.com/2009-07-21/keetologys-mootools-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
