<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Ivan Teoh</title>
	
	<link>http://www.ivanteoh.com</link>
	<description>Something Personal Yet Public</description>
	<lastBuildDate>Sat, 27 Aug 2011 04:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/IvanTeoh" /><feedburner:info uri="ivanteoh" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Cooking: Bubur Cha-Cha</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/2KiyyhJLK7I/</link>
		<comments>http://www.ivanteoh.com/blog/2011/08/cooking-bubur-cha-cha/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 04:09:50 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Food & Drinks]]></category>
		<category><![CDATA[Food]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=2030</guid>
		<description><![CDATA[I just finished cooking bubur cha-cha. Again, it is not as nice as the one in Penang. It is one of my favorite dish during Chinese New Year. It is usually served during the last day (15th) of Chinese New Year for Hokkiens. This version was just sweet potato, sago and black-eyed pea. It is [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished cooking bubur cha-cha. Again, it is not as nice as the one in Penang. It is one of my favorite dish during Chinese New Year. It is usually served during the last day (15th) of Chinese New Year for <a href="http://en.wikipedia.org/wiki/Hokkien" title="http://en.wikipedia.org/wiki/Hokkien">Hokkiens</a>. This version was just sweet potato, sago and black-eyed pea. It is too watery. I will put less water and coconut milk next time.</p>
<h4>Gallery</h4>
<p><a href="http://www.ivanteoh.com/blog/2011/08/cooking-bubur-cha-cha/attachment/27082011115/" rel="attachment wp-att-2031"><img src="http://www.ivanteoh.com/blog/wp-content/uploads/2011/08/27082011115-300x225.jpg" alt="Bubur Cha-Cha" title="Bubur Cha-Cha" width="300" height="225" class="alignnone size-medium wp-image-2031" /></a></p>
<h4>References</h4>
<ul>
<li><a href="http://nyonyafood.rasamalaysia.com/bubur-cha-cha/2/" title="http://nyonyafood.rasamalaysia.com/bubur-cha-cha/2/">Bubur Cha-Cha</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/2KiyyhJLK7I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/08/cooking-bubur-cha-cha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/08/cooking-bubur-cha-cha/</feedburner:origLink></item>
		<item>
		<title>Can’t open Finder app in OS X Lion</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/GEErq92yh30/</link>
		<comments>http://www.ivanteoh.com/blog/2011/07/cant-open-finder-app-in-os-x-lion/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 00:20:47 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[OS X Lion]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1989</guid>
		<description><![CDATA[If you are having problem on opening &#8216;Finder&#8217; app, solution is here. First, &#8216;command + option + esc&#8217;, then click on &#8216;Finder&#8217;, lastly select &#8216;relaunch&#8217; button.
Another solution is uncheck &#8216;Reopen windows when logging back in&#8217; on &#8216;Shut Down&#8230;&#8217; dialog.
Gallery



]]></description>
			<content:encoded><![CDATA[<p>If you are having problem on opening &#8216;Finder&#8217; app, solution is <a href="https://discussions.apple.com/message/15671196" title="Can't open the finder or any of my files">here</a>. First, &#8216;command + option + esc&#8217;, then click on &#8216;Finder&#8217;, lastly select &#8216;relaunch&#8217; button.<br />
Another solution is uncheck &#8216;Reopen windows when logging back in&#8217; on &#8216;Shut Down&#8230;&#8217; dialog.</p>
<h4>Gallery</h4>
<ul class="no-list-style">
<li><a href="http://www.ivanteoh.com/blog/2011/07/cant-open-finder-app-in-os-x-lion/finder/" rel="attachment wp-att-2018"><img src="http://www.ivanteoh.com/blog/wp-content/uploads/2011/07/finder-300x139.png" alt="finder" title="finder" width="300" height="139" class="alignnone size-medium wp-image-2018" /></a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/GEErq92yh30" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/07/cant-open-finder-app-in-os-x-lion/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/07/cant-open-finder-app-in-os-x-lion/</feedburner:origLink></item>
		<item>
		<title>Where is Macintosh HD in OS X Lion</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/ZNFR8g8SgiA/</link>
		<comments>http://www.ivanteoh.com/blog/2011/07/where-is-macintosh-hd-in-os-x-lion/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 13:41:39 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[OS X Lion]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1969</guid>
		<description><![CDATA[I just updated my Mac with OS X Lion. After playing a while, I realise I can&#8217;t find &#8216;Macintosh HD&#8217;. It no longer at left-side bar in Finder. I need it. So I came out with a solution as below.

Right click on &#8216;Application&#8217; and click &#8216;Open Enclosing Folder&#8217;. It will open &#8216;Macintosh HD&#8217; folder in [...]]]></description>
			<content:encoded><![CDATA[<p>I just updated my Mac with OS X Lion. After playing a while, I realise I can&#8217;t find &#8216;Macintosh HD&#8217;. It no longer at left-side bar in Finder. I need it. So I came out with a solution as below.</p>
<ol>
<li>Right click on &#8216;Application&#8217; and click &#8216;Open Enclosing Folder&#8217;. It will open &#8216;Macintosh HD&#8217; folder in new window.</li>
<li>Drag the top center icon, disc, to the left-side bar in Finder under &#8216;Favorites&#8217;.</li>
</ol>
<p>Now, I have &#8216;Macintosh HD&#8217; folder as favorited folder in Finder.</p>
<h4>Gallery</h4>
<ul class="no-list-style">
<li><a href="http://www.ivanteoh.com/blog/2011/07/where-is-macintosh-hd-in-os-x-lion/step1/" rel="attachment wp-att-1985"><img src="http://www.ivanteoh.com/blog/wp-content/uploads/2011/07/Step1-300x200.png" alt="Step 1" title="Step 1" width="300" height="200" class="alignnone size-medium wp-image-1985" /></a></li>
<li>
<a href="http://www.ivanteoh.com/blog/2011/07/where-is-macintosh-hd-in-os-x-lion/step2/" rel="attachment wp-att-1986"><img src="http://www.ivanteoh.com/blog/wp-content/uploads/2011/07/Step2-300x200.png" alt="Step 2" title="Step 2" width="300" height="200" class="alignnone size-medium wp-image-1986" /></a></li>
</ul>
<h4>Updates</h4>
<h3>22 Jul 2011</h3>
<p>Another solution is open &#8216;Finder Preferences&#8217;, select / check &#8216;Hard disks&#8217; on &#8216;Sidebar&#8217; tab under &#8216;Devices&#8217; section.</p>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/ZNFR8g8SgiA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/07/where-is-macintosh-hd-in-os-x-lion/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/07/where-is-macintosh-hd-in-os-x-lion/</feedburner:origLink></item>
		<item>
		<title>D3: Tutorial – Scale graph</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/Q9A0PkxxaBk/</link>
		<comments>http://www.ivanteoh.com/blog/2011/07/d3-tutorial-scale-graph/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 11:47:32 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[D3]]></category>
		<category><![CDATA[Data Visualization]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1965</guid>
		<description><![CDATA[First Protovis, now D3. Both are works from Mike Bostock. Both are data visualization JavaScript libraries. 
This tutorial we’re going to create a basic dot graph with scalable y-axis. It is adapted from one of the examples in D3, dot.html.
Step 1: Default html
First of all, we create a default html that contains a div for [...]]]></description>
			<content:encoded><![CDATA[<p>First <a href=”http://mbostock.github.com/protovis/”>Protovis</a>, now <a href=”http://mbostock.github.com/d3/”>D3</a>. Both are works from <a href=”http://bost.ocks.org/mike”>Mike Bostock</a>. Both are data visualization JavaScript libraries. </p>
<p>This tutorial we’re going to create a basic dot graph with scalable y-axis. It is adapted from one of the examples in D3, <a href=”https://github.com/mbostock/d3/blob/master/examples/dot/dot.html”>dot.html</a>.</p>
<h3>Step 1: Default html</h3>
<p>First of all, we create a default html that contains a <code>div</code> for input button and another for the graph. We also link the d3 JavaScript library. The rest of tutorial will be concentrate of JavaScript code that will be written after the comment, “Scale graph code here.”<br />
<script src="https://gist.github.com/1075321.js?file=index.html"></script></p>
<h3>Step 2: Random data</h3>
<p>We need to generate some random data using <code>Math.random()</code>. We create <code>randomData</code> function for returning a list of ten x and y values. For example, <code>[{“x”: 0, “y”: 0.3}, {“x”: 0.1, “y”: 0.4}, ...]</code><br />
<script src="https://gist.github.com/1075321.js?file=step2.js"></script></p>
<h3>Step 3: Maximum value of y-axis</h3>
<p>For this tutorial, only y axis values are random. We need to get maximum value of the y axis using <code>d3.max</code>, in order to scale the y axis based on the maximum value of the data.<br />
<script src="https://gist.github.com/1075321.js?file=step3.js"></script></p>
<h3>Step 4: Ceil value</h3>
<p>Sometime, the maximum value doesn’t suitable for domain range in scale axis. For example, 0.33333. Mike suggested a <a href=”http://groups.google.com/group/d3-js/msg/3024300d991886ca”>method</a> to increase the size of domain to next highest rounded value.<br />
<script src="https://gist.github.com/1075321.js?file=step4.js"></script></p>
<h3>Step 5: SVG container</h3>
<p>Now, we determine the size of the graph, which are <code>w</code> and <code>h</code> for width and height. We need a svg container for the graph. We will append it inside <code>#mainGraph div</code> with width and height attributes. This is optional, which offset the graph with modify coordinate using <code>translate in transform</code> in a group. The <code>&lt;g&gt;</code> element is used to group SVG shapes together. For example, <code>&lt;g transform="translate(50,50)"&gt;</code> will translate coordinate ["x": 50, "y": 50] as zero in the that group.<br />
<script src="https://gist.github.com/1075321.js?file=step5.js"></script></p>
<h3>Step 6: Rulers</h3>
<p>Now, we add both x and y axises line grids and labels. We also notice that d3 supports css style. We make &#8220;#ccc&#8221; colour stroke style for both x and y line grids.<br />
<script src="https://gist.github.com/1075321.js?file=step6.js"></script></p>
<h3>Step 7: Dots</h3>
<p>This is the last step for the dots graph. All the dots are paths. What kind of symbols of the path is determined by <code>d</code> attribute. We also add title attribute in the path, so that when mouse is hovering the dots, tool tip is shown. Color of the dots fill is changed too. After you completed this steps, we will see a basic dot graph.<br />
<script src="https://gist.github.com/1075321.js?file=step7.js"></script></p>
<h3>Step 8: Update button</h3>
<p>This step is explaining what will happen after update button is clicked. Before that, we need to add <code>onclick</code> attribute in button type input with the update function name. For example, <code>&lt;input name="updateButton" type="button" value="Update" onclick="updateData()"/&gt;</code>. In the update function, we will get a new data list from <code>randomData</code> function. Then get the maximum ceil value, which is similar in <code>initData</code> function. Since, we are only want to rescale the y axis, we will select <code>g.y</code>. Make sure to select their parent, <code>#mainGraph svg g</code>, first before selecting them, in order to append the extra line grid in the right parent. For updating the line grids and labels, we are going to use update, <a href="http://mbostock.github.com/d3/#enter_and_exit">enter and exit</a> selections. Since we are append new line grid and label, we need to set all the attributes that are needed. On the other hand, we only update attributes that need to be changes in update and exit selections. Lastly, don&#8217;t forget about updating the dots data too.<br />
<script src="https://gist.github.com/1075321.js?file=step8.js"></script></p>
<h3>Step 9: Summary</h3>
<p>This tutorial is written based on my personal understanding on <a href=”http://mbostock.github.com/d3/”>D3</a>. I am still learning. Any feedback are welcome.<br />
<script src="https://gist.github.com/1075123.js?file=index.html"></script></p>
<h4>Updates</h4>
<h3>15 Jul 2011</h3>
<p>Ricardo mentions transitioning scales example, <a href="http://bl.ocks.org/1071269" title="Date Ticks">Date Ticks</a> by <a href="https://github.com/mbostock" title="Mike Bostock">mbostock</a>.</p>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/Q9A0PkxxaBk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/07/d3-tutorial-scale-graph/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/07/d3-tutorial-scale-graph/</feedburner:origLink></item>
		<item>
		<title>Cooking: Spicy Pumpkin Risotto</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/Kxmj41fZdXI/</link>
		<comments>http://www.ivanteoh.com/blog/2011/06/cooking-spicy-pumpkin-risotto/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 09:13:16 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Food & Drinks]]></category>
		<category><![CDATA[Food]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1914</guid>
		<description><![CDATA[Tonight dinner is spicy pumpkin risotto. The recipe was from the italian gardener. our favourite food blog, King Arthur Flour – Baking Banter.  
Gallery

References

Spicy Pumpkin Risotto

]]></description>
			<content:encoded><![CDATA[<p>Tonight dinner is spicy pumpkin risotto. The recipe was from <a href="http://www.theitaliangardener.com.au/" title="http://www.theitaliangardener.com.au/">the italian gardener</a>. our favourite food blog, King Arthur Flour – Baking Banter.  </p>
<h4>Gallery</h4>
<p><a href="http://www.ivanteoh.com/blog/wp-content/uploads/2011/06/17062011081.jpg"><img class="alignnone size-full wp-image-6" src="http://www.ivanteoh.com/blog/wp-content/uploads/2011/06/17062011081.jpg" /></a></p>
<h4>References</h4>
<ul>
<li><a href="http://www.theitaliangardener.com.au/pages/Spicey-Pumpkin-Risotto.html" title="http://www.theitaliangardener.com.au/pages/Spicey-Pumpkin-Risotto.html">Spicy Pumpkin Risotto</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/Kxmj41fZdXI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/06/cooking-spicy-pumpkin-risotto/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/06/cooking-spicy-pumpkin-risotto/</feedburner:origLink></item>
		<item>
		<title>Javascript: 101 Week 5 Track 2</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/jSeyOlXWWrE/</link>
		<comments>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-2/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 13:53:21 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Tech & Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1930</guid>
		<description><![CDATA[On week 5 track 2, we continue study chapter 12 and 13 on Eloquent Javascript. Both chapters are related to document-object model and browser events.
Reflection

What factors make accessing nodes according to their structural order (by using the &#8216;firstChild&#8217; and &#8216;lastChild&#8217; properties, for example) an inefficient and potentially unreliable approach? What alternatives are available?We have been [...]]]></description>
			<content:encoded><![CDATA[<p>On week 5 track 2, we continue study chapter 12 and 13 on <a href="http://eloquentjavascript.net/">Eloquent Javascript</a>. Both chapters are related to document-object model and browser events.</p>
<h3>Reflection</h3>
<ol>
<li><strong>What factors make accessing nodes according to their structural order (by using the &#8216;firstChild&#8217; and &#8216;lastChild&#8217; properties, for example) an inefficient and potentially unreliable approach? What alternatives are available?</strong><br />We have been accessing nodes by going through a series of <code>firstChild</code> and <code>lastChild</code> properties. This can work, but it is verbose and easy to break ― if we add another node at the start of our <code>document, document.body.firstChild</code> no longer refers to the <code>h1</code> element, and code which assumes it does will go wrong. On top of that, some browsers will add text-nodes for things like spaces and newlines between tags, while others do not, so that the exact layout of the DOM tree can vary. An alternative to this is to give elements that you need to have access to an <code>id</code> attribute. We can get the element by calling <code>getElementById</code> function.</li>
<li><strong>How does CSS play a role in JavaScript&#8217;s interactive possibilities with the DOM? What are a few of the techniques related to this?</strong><br />Closely tied to HTML and the document-object model is the topic of style-sheets. It is a big topic, and I will not discuss it entirely, but some understanding of style-sheets is necessary for a lot of interesting JavaScript techniques, so we will go over the basics.<br />In old-fashioned HTML, the only way to change the appearance of elements in a document was to give them extra attributes or to wrap them in extra tags, such as <code>center</code> to center them horizontally, or <code>font</code> to change the font style or colour. Most of the time, this meant that if you wanted the paragraphs or the tables in your document to look a certain way, you had to add a bunch of attributes and tags to every single one of them. This quickly adds a lot of noise to such documents, and makes them very painful to write or change by hand.<br />Style-sheets are a way to make statements like &#8216;in this document, all paragraphs use the Comic Sans font, and are purple, and all tables have a thick green border&#8217;. You specify them once, at the top of the document or in a separate file, and they affect the whole document.<br />Classes are a concept related to styles. If you have different kinds of paragraphs, ugly ones and nice ones for example, setting the style for all <code>p</code> elements is not what you want, so classes can be used to distinguish between them. And this is also the meaning of the <code>className</code> property which was briefly mentioned for the <code>setNodeAttribute</code> function. The <code>style</code> attribute can be used to add a piece of style directly to an element.<br />There is much more to styles: Some styles are inherited by child nodes from parent nodes, and interfere with each other in complex and interesting ways, but for the purpose of DOM programming, the most important thing to know is that each DOM node has a <code>style</code> property, which can be used to manipulate the style of that node, and that there are a few kinds of styles that can be used to make nodes do extraordinary things.</li>
<li><strong>Identify some of the browser events JavaScript is capable of interpreting. What might the practical applications be?</strong><br />There are many browser events that JavaScript is capable of interpreting. First one that we can think of straight away is button click. This does in fact work across browsers, but it has an important drawback ― you can only attach one handler to an element. Most of the time, one is enough, but there are cases, especially when a program has to be able to work together with other programs (which might also be adding handlers), that this is annoying.</li>
</ol>
<h3>Homework</h3>
<ul>
<li><strong>Write a function <code>asHTML</code> which, when given a DOM node, produces a string representing the HTML text for that node and its children. You may ignore attributes, just show nodes as <code><nodename></code>. The <code>escapeHTML</code> function from chapter 10 is available to properly escape the content of text nodes. Hint: Recursion!</strong><br /><script src="http://pastebin.com/embed_js.php?i=6CFyxqsj"></script></li>
<li><strong>Write the convenient function <code>removeElement</code> which removes the DOM node it is given as an argument from its parent node.</strong><br /><script src="http://pastebin.com/embed_js.php?i=QbARdySV"></script></li>
<li><strong>Write a function called <code>registerEventHandler</code> to wrap the incompatibilities of these two models. It takes three arguments: first a DOM node that the handler should be attached to, then the name of the event type, such as &#8220;<code>click</code>&#8221; or &#8220;<code>keypress</code>&#8220;, and finally the handler function. To determine which method should be called, look for the methods themselves ― if the DOM node has a method called <code>attachEvent</code>, you may assume that this is the correct method. Note that this is much preferable to directly checking whether the browser is Internet Explorer. If a new browser arrives which uses Internet Explorer&#8217;s model, or Internet Explorer suddenly switches to the standard model, the code will still work. Both are rather unlikely, of course, but doing something in a smart way never hurts.</strong><br /><script src="http://pastebin.com/embed_js.php?i=3a4g1Km3"></script></li>
<li><strong>Create an HTML page and some Javascript to allow a user to add n numbers. First display a simple form with the question &#8220;How many numbers do you want to add (max is 10)&#8221;. The user should enter a number between 2 to 10 and click on a button in the form. You have to validate the answer. If the user has entered a correct value (between 2 and 10), then dynamically create a form with n text input fields and an &#8220;Add&#8221; button. Once the form is displayed the user will enter n numbers in the n input fields and when they click on the &#8220;Add&#8221; button, dynamically create a span element with the result. You will have to perform validation on the values entered in the input fields to make sure that they are numbers. If they are not numbers, display an alert dialogue with an error message.</strong><br /><script src="http://pastebin.com/embed_js.php?i=VNS7aUMW"></script></li>
</ul>
<h4>References</h4>
<ul>
<li><a href="http://p2pu.org/webcraft/javascript-101">/*#p2pu-Jan2011-javascript101*/</a></li>
<li><a href="http://webcraftp2p.appspot.com/courses/course/javascript101p2pujanuary2011/unit/5">JAVASCRIPT 101 &#8211; P2PU Week 5</a></li>
<li><a href="http://javascript101.pimpo.org/">Planet Javascript101</a></li>
<li><a href="http://www.crockford.com/">Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/jSeyOlXWWrE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-2/</feedburner:origLink></item>
		<item>
		<title>Javascript: 101 Week 5 Track 1</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/ia-XLsFfPYg/</link>
		<comments>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-1/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 09:17:25 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Tech & Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1926</guid>
		<description><![CDATA[On this week, we continue watching &#8216;An Incovenient API &#8211; The Theory of the DOM&#8217; part 2 as below by Douglas Crockford
Douglas Crockford: &#34;Theory of the DOM&#34; (2 of 3) @ Yahoo! Video
Reflection

Why is it better to use either trickling or bubbling of events? Why not just give the event to the node on which [...]]]></description>
			<content:encoded><![CDATA[<p>On this week, we continue watching &#8216;An Incovenient API &#8211; The Theory of the DOM&#8217; part 2 as below by Douglas Crockford</p>
<p><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=996002&#038;vid=111583&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w327/111583_100_70.jpeg%3Fx%3D158%26y%3D111%26sig%3DG2f65fsDiJybzRbHkElMzw--&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=996002&#038;vid=111583&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w327/111583_100_70.jpeg%3Fx%3D158%26y%3D111%26sig%3DG2f65fsDiJybzRbHkElMzw--&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111583/996002">Douglas Crockford: &quot;Theory of the DOM&quot; (2 of 3)</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></p>
<h3>Reflection</h3>
<ol>
<li><strong>Why is it better to use either trickling or bubbling of events? Why not just give the event to the node on which it was invoked?</strong><br />Trickling is an event capturing pattern which provides compatibility with the Netscape 4 model. Avoid it. On the other hand, bubbling means that the event is given to the target, and then its parent, and then its parent, and so on until the event is cancelled. Bubble is very useful specially we have a very large set of objects. Supposedly we have 100 draggable objects. We could attach 100 sets of event handlers to those objects. Or we could attach one set of event handlers to the container of the 100 objects.</li>
<li><strong>Can you think of one situation where you would want to prevent the browser from submitting a form after a user has clicked on the &#8216;submit&#8217; button? How would you achieve this?</strong><br />Cancel bubbling is to keep the parent nodes from seeing the event.<script src="http://pastebin.com/embed_js.php?i=sK4hz7m6"></script>Cancel bubbling is not enough. After all the bubbling is finished, the browser will then do what it&#8217;s normally does. An event handler as below can prevent a browser action associated with the event (such as submitting a form).<script src="http://pastebin.com/embed_js.php?i=1Ft2EbWY"></script></li>
</ol>
<h3>Homework</h3>
<p>Since track 1 is the same as track 2 in week 5, the answer for the homework will be in track 2 post.</p>
<h4>References</h4>
<ul>
<li><a href="http://p2pu.org/webcraft/javascript-101">/*#p2pu-Jan2011-javascript101*/</a></li>
<li><a href="http://webcraftp2p.appspot.com/courses/course/javascript101p2pujanuary2011/unit/5">JAVASCRIPT 101 &#8211; P2PU Week 5</a></li>
<li><a href="http://javascript101.pimpo.org/">Planet Javascript101</a></li>
<li><a href="http://www.crockford.com/">Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/ia-XLsFfPYg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-5-track-1/</feedburner:origLink></item>
		<item>
		<title>Javascript: 101 Week 4</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/FxLf4AfspFk/</link>
		<comments>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-4/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 10:35:47 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Tech & Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1908</guid>
		<description><![CDATA[Since track 2 is the subset for track 1 in week 4, so we combine them both to this post. On this week, beside watching &#8216;An Incovenient API &#8211; The Theory of the DOM&#8217; as below by Douglas Crockford, we also need to reading these articles below on understanding on DOM.

Aticle: Traversing the DOM
Introduction to [...]]]></description>
			<content:encoded><![CDATA[<p>Since track 2 is the subset for track 1 in week 4, so we combine them both to this post. On this week, beside watching &#8216;An Incovenient API &#8211; The Theory of the DOM&#8217; as below by Douglas Crockford, we also need to reading these articles below on understanding on DOM.</p>
<ul>
<li><a href="http://dev.opera.com/articles/view/traversing-the-dom/">Aticle: Traversing the DOM</a></li>
<li><a href="http://www.quirksmode.org/dom/intro.html">Introduction to modifying the DOM</a></li>
<li><a href="http://www.javascript-coder.com/javascript-form/javascript-get-form.phtml">How to access a form element with Javascript</a></li>
</ul>
<p><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=992708&#038;vid=111582&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111582_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=992708&#038;vid=111582&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111582_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111582/992708">Douglas Crockford: &quot;Theory of the DOM &quot; (1 of 3)</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></p>
<h3>Reflection</h3>
<ol>
<li><strong>There were two key innovations to the original (fetch-parse-flow-paint) linear workflow that the Mosaic browser used to render web pages. One allowed for a perception of faster rendering, and the other allowed for us to use AJAX. Explain both?</strong><br />This article, <a href="http://gregmoreno.ca/the-inconvenient-truth-on-website-performance/">The Inconvenient Truth on website performance </a>, do explain clearly.</li>
<li><strong>What are the roles of &#8216;name&#8217; and &#8216;id&#8217; attributes in HTML tags? What is an appropriate use of both?</strong><br />From <a href="http://bytes.com/topic/javascript/answers/92702-when-use-id-when-use-name-html-tag">bytes&#8217;s forum</a>, <a href="http://www.crockford.com/">Douglas Crockford</a> said &#8220;name is used to annotate POST data in forms. id is used to identify elements for scripting and styling. Some browsers used them interchangeably, which is confusing.&#8221;</li>
<li><strong>Which pointers does each node in the DOM tree typically have?</strong><br />From <a href="http://dev.opera.com/articles/view/traversing-the-dom/">Aticle: Traversing the DOM</a>, each node in the DOM tree typically point to &#8216;parent&#8217;, &#8216;child&#8217; and &#8216;sibling&#8217;.</li>
<li><strong>Given a node object from a DOM tree, how do we determine if it is a text node or a regular node?</strong><br />From <a href="http://dev.opera.com/articles/view/traversing-the-dom/">Aticle: Traversing the DOM</a>, a text node’s <code>nodeName</code> property is “#text”.</li>
</ol>
<h3>Homework</h3>
<ul>
<li><strong>Download the source for the web page &#8216;http://www.useit.com/about/nographics.html&#8217;. In the source page itself, write a Javascript function which counts the number of text nodes in the document and shows the count in an alert dialogue. You can choose how you want to trigger the function (through a button click, link click, or any other event).</strong><br /><script src="http://pastebin.com/embed_js.php?i=YZizRMJt"></script></li>
<li><strong>Change the example above so that instead of displaying the count in an alert dialogue, it is displayed in a span tag in the HTML page itself.</strong><br /><script src="http://pastebin.com/embed_js.php?i=EE8nHmEZ"></script></li>
<li><strong>Add a link besides the button, such that when the link is click, it changes the style on the span tag to make it&#8217;s contents bold.</strong><br /><script src="http://pastebin.com/embed_js.php?i=cwABzLiE"></script></li>
</ul>
<h4>References</h4>
<ul>
<li><a href="http://p2pu.org/webcraft/javascript-101">/*#p2pu-Jan2011-javascript101*/</a></li>
<li><a href="http://webcraftp2p.appspot.com/courses/course/javascript101p2pujanuary2011/unit/4">JAVASCRIPT 101 &#8211; P2PU Week 4</a></li>
<li><a href="http://javascript101.pimpo.org/">Planet Javascript101</a></li>
<li><a href="http://www.crockford.com/">Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/FxLf4AfspFk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-4/</feedburner:origLink></item>
		<item>
		<title>Javascript: 101 Week 3 Track 2</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/MctDELwNTWM/</link>
		<comments>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-2/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 08:26:46 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Tech & Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1878</guid>
		<description><![CDATA[On track 2 week 3, we are continuing reading Eloquent Javascript ebook on chapter 6: Functional Programming and JavaScript code style.
Reflection

Why is it helpful to break a programs logic into functions?As programs get bigger, it helps us easy to understand the program logic.
In JavaScript, functions are first class objects. What does it mean to be [...]]]></description>
			<content:encoded><![CDATA[<p>On track 2 week 3, we are continuing reading <a href="http://eloquentjavascript.net/">Eloquent Javascript</a> ebook on chapter 6: Functional Programming and <a href="http://javascript.crockford.com/code.html">JavaScript code style</a>.</p>
<h3>Reflection</h3>
<ol>
<li><strong>Why is it helpful to break a programs logic into functions?</strong><br />As programs get bigger, it helps us easy to understand the program logic.</li>
<li><strong>In JavaScript, functions are first class objects. What does it mean to be a first class object?</strong><br />From <a href="http://en.wikipedia.org/wiki/First-class_object">Wikipedia</a>, first class object is an entity that can be passed as a parameter, returned from a subroutine, or assigned into a variable.</li>
<li><strong>What are anonymous functions, and where would you use them?</strong><br />In computing, an <a href="http://en.wikipedia.org/wiki/Anonymous_function">anonymous functions</a> is a function (or a subroutine) defined, and possibly called, without being bound to an identifier. They are convenient to pass as an argument to a higher-order function and are ubiquitous in languages with first-class functions.</li>
<li><strong>Why is it important to follow good code style in your code?</strong><br />From <a href="http://javascript.crockford.com/code.html">this article</a>, good code style can help in reducing the brittleness of programs.</li>
</ol>
<h3>Homework</h3>
<p>Week 3 homework for track 2 are the same as track 1. Here will be the answers that is recommended by <a href="http://www.jslint.com/">JSLint</a> for exercises 6.1 to 6.5. <a href="http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-1/">Track 1</a> will be showing  the original answer for exercises 6.1 to 6.5.</p>
<ul>
<li><strong>Ex. 6.1: Write a function <code>countZeroes</code>, which takes an array of numbers as its argument and returns the amount of zeroes that occur in it. Use <code>reduce</code>. Then, write the higher-order function <code>count</code>, which takes an array and a test function as arguments, and returns the amount of elements in the array for which the test function returned <code>true</code>. Re-implement <code>countZeroes</code> using this function.</strong><br /><script src="http://pastebin.com/embed_js.php?i=WfCthUFR"></script><script src="http://pastebin.com/embed_js.php?i=wTEShan2"></script></li>
<li><strong>Ex. 6.2: Write a function <code>processParagraph</code> that, when given a paragraph string as its argument, checks whether this paragraph is a header. If it is, it strips of the &#8216;%&#8217; characters and counts their number. Then, it returns an object with two properties, <code>content</code>, which contains the text inside the paragraph, and <code>type</code>, which contains the tag that this paragraph must be wrapped in, &#8220;p&#8221; for regular paragraphs, &#8220;h1&#8243; for headers with one &#8216;%&#8217;, and &#8220;hX&#8221; for headers with X &#8216;%&#8217; characters. Remember that strings have a <code>charAt</code> method that can be used to look at a specific character inside them.</strong><br /><script src="http://pastebin.com/embed_js.php?i=VAUJEe4S"></script></li>
<li><strong>Ex. 6.3: Build a function <code>splitParagraph</code> which, given a paragraph string, returns an array of paragraph fragments. Think of a good way to represent the fragments. The method <code>indexOf</code>, which searches for a character or sub-string in a string and returns its position, or -1 if not found, will probably be useful in some way here. This is a tricky algorithm, and there are many not-quite-correct or way-too-long ways to describe it. If you run into problems, just think about it for a minute. Try to write inner functions that perform the smaller actions that make up the algorithm.</strong><br /><script src="http://pastebin.com/embed_js.php?i=YCNUQCEk"></script></li>
<li><strong>Ex. 6.4: Looking back at the example HTML document if necessary, write an <code>image</code> function which, when given the location of an image file, will create an <code>img</code> HTML element.</strong><br /><script src="http://pastebin.com/embed_js.php?i=kbSNWckG"></script></li>
<li><strong>Ex. 6.5: Write a function <code>renderFragment</code>, and use that to implement another function <code>renderParagraph</code>, which takes a paragraph object (with the footnotes already filtered out), and produces the correct HTML element (which might be a paragraph or a header, depending on the <code>type</code> property of the paragraph object). This function might come in useful for rendering the footnote references:<br />
function footnote(number) {<br />
  return tag(&#8220;sup&#8221;, [link("#footnote" + number,<br />
                          String(number))]);<br />
}<br />
A <code>sup</code> tag will show its content as &#8216;superscript&#8217;, which means it will be smaller and a little higher than other text. The target of the link will be something like <code>"#footnote1"</code>. Links that contain a &#8216;#&#8217; character refer to &#8216;anchors&#8217; within a page, and in this case we will use them to make it so that clicking on the footnote link will take the reader to the bottom of the page, where the footnotes live. The tag to render emphasized fragments with is <code>em</code>, and normal text can be rendered without any extra tags.</strong><br /><script src="http://pastebin.com/embed_js.php?i=BG6UMAnA"></script></li>
</ul>
<h4>References</h4>
<ul>
<li><a href="http://p2pu.org/webcraft/javascript-101">/*#p2pu-Jan2011-javascript101*/</a></li>
<li><a href="http://webcraftp2p.appspot.com/courses/course/javascript101p2pujanuary2011/unit/3">JAVASCRIPT 101 &#8211; P2PU Week 3</a></li>
<li><a href="http://javascript101.pimpo.org/">Planet Javascript101</a></li>
<li><a href="http://www.crockford.com/">Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/MctDELwNTWM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-2/</feedburner:origLink></item>
		<item>
		<title>Javascript: 101 Week 3 Track 1</title>
		<link>http://feedproxy.google.com/~r/IvanTeoh/~3/eYdhxCifzAM/</link>
		<comments>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-1/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 08:26:20 +0000</pubDate>
		<dc:creator>Ivan</dc:creator>
				<category><![CDATA[Tech & Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.ivanteoh.com/?p=1873</guid>
		<description><![CDATA[On track 1 week 3, we are continuing understanding JavaScript through Douglas Crockford&#8217; video 3 and video 4 as below.
Douglas Crockford: &#34;The JavaScript Programming Language&#34;/3 of 4 @ Yahoo! Video
Douglas Crockford: &#34;The JavaScript Programming Language&#34;/4 of 4 @ Yahoo! Video
Reflection

In Javascript, functions are first class objects. What does it mean to be a first class [...]]]></description>
			<content:encoded><![CDATA[<p>On track 1 week 3, we are continuing understanding JavaScript through Douglas Crockford&#8217; video 3 and video 4 as below.</p>
<p><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=1710607&#038;vid=111595&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111595_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=1710607&#038;vid=111595&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111595_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111595/1710607">Douglas Crockford: &quot;The JavaScript Programming Language&quot;/3 of 4</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></p>
<p><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=1710658&#038;vid=111596&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111596_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=1710658&#038;vid=111596&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111596_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111596/1710658">Douglas Crockford: &quot;The JavaScript Programming Language&quot;/4 of 4</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></p>
<h3>Reflection</h3>
<ol>
<li><strong>In Javascript, functions are first class objects. What does it mean to be a first class object?</strong><br />From <a href="http://en.wikipedia.org/wiki/First-class_object">Wikipedia</a>, first class object is an entity that can be passed as a parameter, returned from a subroutine, or assigned into a variable.</li>
<li><strong>Functions and variables share the same namespace. What does this mean and what important implication does this have?</strong><br />We can have same name for both function and variable. They are the same in JavaScript.</li>
<li><strong>Douglas Crockford equates JavaScript functions with Lambdas, and also mentions that they are a secure construct. Can you do some research and reflect on what he means by &#8216;secure construct&#8217;?</strong><br />From the presentation, he said it can constraint the scope.</li>
<li><strong>Can you explain the concept of a closure.</strong><br /><a href="http://jibbering.com/faq/notes/closures/">Here</a> got very clear explanation on closure. A &#8220;closure&#8221; is an expression (typically a function) that can have free variables together with an environment that binds those variables (that &#8220;closes&#8221; the expression).</li>
<li><strong>What is the difference between a function and a method?</strong><br />A function in an object is called a method.</li>
<li><strong>In Javascript there is no implicit type checking of arguments passed to functions. This could lead to bugs if programmers are not careful about what they pass to functions. If you create a function, how would you protect it from well meaning but careless programmers?</strong><br />One way, we can use function&#8217;s <code>arguments</code> property to verify on each arguments. When a function is invoked, in addition to its parameters, it also gets a special parameter called <code>arguments</code>. It contains all of the arguments from the invocation. It is an array-like object. We can use <code>arguments.length</code> to verify the total of arguments are passed.</li>
<li><strong>JavaScript functions have implicit access to something called this. this points to different things depending on how the function was created. Can you explain why we need this, and what it represents in different type of functions.</strong><br />From the presentation, <code>this</code> is an extra parameter. Its value depends on the calling form. It also gives methods access to their objects and it is bound at invocation time. If the invocation form is function, <code>functionObject(arguments)</code>, then <code>this</code> is the global object. If the invocation form is method, <code>thisObject.methodName(arguments)</code>, then <code>this</code> is the object. Finally, if the invocation form is constructor, <code>new functionObject(arguments)</code>, <code>this</code> is the new object.</li>
<li><strong>Why doesn&#8217;t JavaScript have a cast operator?</strong><br />The <code><a href="http://www.crasseux.com/books/ctutorial/The-cast-operator.html">cast operator</a></code> converts one type into another. In C, its general form is <code>(type) variable</code>. Because it uses other way, for example using <code>parseInt()</code> function to convert string type to integer type.</li>
<li><strong>What is reflection and why is it easy in JavaScript (you may need to do research to answer this question)?</strong><br /><a href="http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29">Reflection</a> is the process by which a computer program can observe and modify its own structure and behavior at runtime. Every object is a separate namespace. Use an object to organize your variables and functions.</li>
</ol>
<h3>Homework</h3>
<p>Week 3 homework for track 1 are the same as track 2. Here will be exercises 6.1 to 6.5. <a href="http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-2/">Track 2</a> will be showing the answers that is recommended by <a href="http://www.jslint.com/">JSLint</a>.</p>
<ul>
<li><strong>Ex. 6.1: Write a function <code>countZeroes</code>, which takes an array of numbers as its argument and returns the amount of zeroes that occur in it. Use <code>reduce</code>. Then, write the higher-order function <code>count</code>, which takes an array and a test function as arguments, and returns the amount of elements in the array for which the test function returned <code>true</code>. Re-implement <code>countZeroes</code> using this function.</strong><br /><script src="http://pastebin.com/embed_js.php?i=NwwtUv5D"></script><script src="http://pastebin.com/embed_js.php?i=1ee6Zhch"></script></li>
<li><strong>Ex. 6.2: Write a function <code>processParagraph</code> that, when given a paragraph string as its argument, checks whether this paragraph is a header. If it is, it strips of the &#8216;%&#8217; characters and counts their number. Then, it returns an object with two properties, <code>content</code>, which contains the text inside the paragraph, and <code>type</code>, which contains the tag that this paragraph must be wrapped in, &#8220;p&#8221; for regular paragraphs, &#8220;h1&#8243; for headers with one &#8216;%&#8217;, and &#8220;hX&#8221; for headers with X &#8216;%&#8217; characters. Remember that strings have a <code>charAt</code> method that can be used to look at a specific character inside them.</strong><br /><script src="http://pastebin.com/embed_js.php?i=d9DxgeDq"></script></li>
<li><strong>Ex. 6.3: Build a function <code>splitParagraph</code> which, given a paragraph string, returns an array of paragraph fragments. Think of a good way to represent the fragments. The method <code>indexOf</code>, which searches for a character or sub-string in a string and returns its position, or -1 if not found, will probably be useful in some way here. This is a tricky algorithm, and there are many not-quite-correct or way-too-long ways to describe it. If you run into problems, just think about it for a minute. Try to write inner functions that perform the smaller actions that make up the algorithm.</strong><br /><script src="http://pastebin.com/embed_js.php?i=nmteFw3q"></script></li>
<li><strong>Ex. 6.4: Looking back at the example HTML document if necessary, write an <code>image</code> function which, when given the location of an image file, will create an <code>img</code> HTML element.</strong><br /><script src="http://pastebin.com/embed_js.php?i=kbSNWckG"></script></li>
<li><strong>Ex. 6.5: Write a function <code>renderFragment</code>, and use that to implement another function <code>renderParagraph</code>, which takes a paragraph object (with the footnotes already filtered out), and produces the correct HTML element (which might be a paragraph or a header, depending on the <code>type</code> property of the paragraph object). This function might come in useful for rendering the footnote references:<br />
function footnote(number) {<br />
  return tag(&#8220;sup&#8221;, [link("#footnote" + number,<br />
                          String(number))]);<br />
}<br />
A <code>sup</code> tag will show its content as &#8216;superscript&#8217;, which means it will be smaller and a little higher than other text. The target of the link will be something like <code>"#footnote1"</code>. Links that contain a &#8216;#&#8217; character refer to &#8216;anchors&#8217; within a page, and in this case we will use them to make it so that clicking on the footnote link will take the reader to the bottom of the page, where the footnotes live. The tag to render emphasized fragments with is <code>em</code>, and normal text can be rendered without any extra tags.</strong><br /><script src="http://pastebin.com/embed_js.php?i=x6FkHYMu"></script></li>
</ul>
<h4>References</h4>
<ul>
<li><a href="http://p2pu.org/webcraft/javascript-101">/*#p2pu-Jan2011-javascript101*/</a></li>
<li><a href="http://webcraftp2p.appspot.com/courses/course/javascript101p2pujanuary2011/unit/3">JAVASCRIPT 101 &#8211; P2PU Week 3</a></li>
<li><a href="http://javascript101.pimpo.org/">Planet Javascript101</a></li>
<li><a href="http://www.crockford.com/">Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/IvanTeoh/~4/eYdhxCifzAM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.ivanteoh.com/blog/2011/02/javascript-101-week-3-track-1/</feedburner:origLink></item>
	</channel>
</rss>

