<?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>The Bloggery of Jason Lydon</title>
	<atom:link href="http://jasonlydon.com/bloggery/feed" rel="self" type="application/rss+xml" />
	<link>http://jasonlydon.com/bloggery</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 05 Dec 2011 21:06:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>HTML5 Input Placeholder Safari Bug</title>
		<link>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug</link>
		<comments>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug#comments</comments>
		<pubDate>Mon, 05 Dec 2011 21:06:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[Placeholder]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=378</guid>
		<description><![CDATA[When using placeholder in text inputs, Safari won&#8217;t respect line-height. The text won&#8217;t appear to be centered vertically. But if you remove the line-height, it will. Just a heads up.]]></description>
			<content:encoded><![CDATA[<p>When using placeholder in text inputs, Safari won&#8217;t respect line-height. The text won&#8217;t appear to be centered vertically. But if you remove the line-height, it will. Just a heads up.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nerd alert: Mike Tyson&#8217;s Punch Out Training all CSS &amp; jQuery</title>
		<link>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery</link>
		<comments>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery#comments</comments>
		<pubDate>Wed, 06 Apr 2011 22:47:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Libraries]]></category>
		<category><![CDATA[NO FLASH]]></category>
		<category><![CDATA[Addy Osmani]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mike Tyson's Punch Out]]></category>
		<category><![CDATA[Spritely]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=371</guid>
		<description><![CDATA[Today I found a blog via a LinkedIn group that loves HTML5. Addy Osmani is the man, no questions asked. So I did a little tutorial off his site doing animation based on a jQuery plugin called Spritely. The end result is the jogging screen from Mike Tyson&#8217;s Punch Out NES game. All HTML, CSS, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I found a blog via a  LinkedIn group that loves HTML5. <a href="http://addyosmani.com/" target="_blank">Addy Osmani</a> is the man, no questions asked. So I did a little tutorial off his site doing animation based on a <a href="http://api.jquery.com/" target="_blank">jQuery</a> plugin called <a href="http://spritely.net" target="_blank">Spritely</a>.</p>
<p><a href="/spritely_test.html"><img src="/img/tyson/screenshot.png" alt="The Mike Tyson's Punch Out training screen done with Spritely" /></a></p>
<p><a href="/spritely_test.html">The end result</a> is the jogging screen from Mike Tyson&#8217;s Punch Out NES game. All HTML, CSS, jQuery &amp; Spritely! I really couldn&#8217;t help myself!</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JS101 Week 3 &#8211; Track 1</title>
		<link>http://jasonlydon.com/bloggery/js101-week-3-track-1</link>
		<comments>http://jasonlydon.com/bloggery/js101-week-3-track-1#comments</comments>
		<pubDate>Thu, 10 Mar 2011 18:02:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[P2PU]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=358</guid>
		<description><![CDATA[So it&#8217;s week 3 in JS101 in my world, but the class actually ended today after 6 weeks. Week 3 appeared to give everyone in class a lot of trouble, hopefully I can bang it out and try to get week 5 &#38; 6 knocked out. Work &#38; school did not want to co-exist for [...]]]></description>
			<content:encoded><![CDATA[<p> So it&#8217;s week 3 in JS101 in my world, but the class actually ended today after 6 weeks. Week 3 appeared to give everyone in class a lot of trouble, hopefully I can bang it out and try to get week 5 &amp; 6 knocked out. Work &amp; school did not want to co-exist for the last few weeks&#8230;</p>
<p>Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. You can discuss them on the forums, and upload them on your blog or any open source repository where your course peers and facilitators can review and comment on them.</p>
<p>Video 3</p>
<div><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></div>
<p>Video 4</p>
<div><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></div>
<p>Questions for reflection (please reflect on your blog and discuss in comments below):</p>
<ul class='p2pu'>
<li>Q: 1. In Javascript, functions are first class objects. What does it mean to be a first class object?<br />
A: According to the video:<br />
1. Functions can be passed, returned, and stored just like any other value<br />
2. Functions inherit from Object and can store name/value pairs<br />
i.e. they are objects and can be manipulated and passed around like just like any other object. Specifically, they are Function objects(<a href='https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope' target='_blank'>source</a>)</li>
<li>Q: 2. Functions and variables share the same namespace. What does this mean and what important implication does this have?<br />
A: This means that variables and functions can have the same name and should not be named the same because it can cause conflict/problems<br />
function foo(){}<br />
expands to<br />
var foo = function foo()();</li>
<li>3. 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;?<br />
A: Lambda comes from the Lambda Calculus and refers to anonymous functions in programming.<br />
Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this.<br />
<strong>Javascript</strong></p>
<pre>
adder = function (x) {
    return function (y) {
        x + y
    }
};
add5 = adder(5);
add5(1) == 6
</pre>
<p>As you can see from the snippet of python and js, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.(<a href='http://stackoverflow.com/questions/16501/what-is-a-lambda-function' target='_blank'>source</a>)</li>
<li>4. Can you explain the concept of a closure.<br />
A: Two one sentence summaries (<a href='http://www.javascriptkit.com/javatutors/closures.shtml' target='_blank'>source</a>):<br />- a closure is the local variables for a function &#8211; kept alive after the function has returned, or<br />
- a closure is a stack-frame which is not deallocated when the function returns. (as if a &#8216;stack-frame&#8217; were malloc&#8217;ed instead of being on the stack!<br />
That same article breaks this out as the definition: &#8220;In JavaScript, if you use the function keyword inside another function, you are creating a closure.&#8221; So if you use something like alert(); inside your function, you are creating closure because the alert exists after/outside the function&#8230;</li>
<li>5. What is the difference between a function and a method?<br />
A: &#8216;A function in an object is called a method.&#8217; That appears to be the only difference.</li>
<li>6. 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?<br />
A: &#8216;We can use “arguments” and check at the very beginning whether the programmers had entered the right number of arguments to the function.&#8217; IE arguments.length. Or we can check for the type we are look for using typeof() = type</li>
<li>7. 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.<br />
A: &#8216;this&#8217; is important because it &#8216;gives methods access to their objects&#8217;<br />
Function form ==> functionObject(arguments) ==> this is set to the global object so we must use var that = this; to have  access to the outer this<br />
Method form ==> thisObject.methodName(arguments) ==> this = thisObject aka the object containing the function<br />
Constructor form ==> new functionObject(arguments) ==> a new object is created and assigned to this.<br />
Apply form ==> undefined in the video&#8230;</li>
<li>8. Why doesn&#8217;t Javascript have a cast operator?<br />
A: &#8220;In javascript, we never cast. An object reference is always an object reference.&#8221; In english, this basically means that js does type casts automatically. However, types can be converted as desired using the conversion functions: String(), Number(), Boolean(), etc.(<a href='http://blog.patrickcollins.me/?p=13' target='_blank'>source</a>)</li>
<li>9. What is reflection and why is it easy in Javascript (you may need to do research to answer this question)?<br />
A: &#8216;Sometimes you want to find out what members an object exposes. There&#8217;s a pretty simple way to do this. A simple for-in statement.&#8217;</p>
<pre>
for(var member in obj){
  alert(member);
};
</pre>
<p>or something like this:</p>
<pre>
for (var member in object) {
	alert('Name: ' + member);
	alert('Value: ' + object[member]);
}
</pre>
</li>
</ul>
<p><strong>Homework:</strong></p>
<p><a href='http://eloquentjavascript.net/chapter6.html' target='_blank'>Exercises 6.1 &#8211; 6.5 from the book Eloquent Javascript</a>. Follow good Javascript style.</p>
<ul class='p2pu'>
<li>Q: 1. <a href='http://eloquentjavascript.net/chapter6.html' target='_blank'>Exercises 6.1 &#8211; 6.5 from the book Eloquent Javascript</a>. Follow good Javascript style.<br />
A: coming soon&#8230;</li>
<li>Q: 2. Run all the exercises you did (6.1 &#8211; 6.5) through <a href='http://www.jslint.com/' target='_blank'>JSLint</a> and change your code to improve it.<br />
A: coming soon&#8230;</li>
</ul>
<p>Run all the exercises you did (6.1 &#8211; 6.5) through <a href='http://www.jslint.com/' target='_blank'>JSLint</a> and change your code to improve it.</p>
<p>#p2pu-Jan2011-javascript101</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/js101-week-3-track-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS101 Week 4</title>
		<link>http://jasonlydon.com/bloggery/js101-week-4</link>
		<comments>http://jasonlydon.com/bloggery/js101-week-4#comments</comments>
		<pubDate>Wed, 09 Mar 2011 18:05:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[P2PU]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=344</guid>
		<description><![CDATA[TRACK 1 &#8211; Javascript Videos Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. [...]]]></description>
			<content:encoded><![CDATA[<p>TRACK 1 &#8211; Javascript Videos<br />
Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. You can discuss them on the forums, and upload them on your blog or any open source repository where your course peers and facilitators can review and comment on them.</p>
<ul>
<li><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></li>
<li><a href="http://dev.opera.com/articles/view/traversing-the-dom/" target="_blank">Article: Traversing the DOM</a></li>
<li><a href="http://www.quirksmode.org/dom/intro.html" target="_blank">Introduction to modifying the DOM</a></li>
<li><a href="http://www.javascript-coder.com/javascript-form/javascript-get-form.phtml" target="_blank">How to access a form element with Javascript</a></li>
</ul>
<p>Questions for reflection (please reflect on your blog and discuss in comments below):</p>
<ul class="p2pu">
<li>Q: 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?<br />
A: 1) The Mosaic engine had a problem with images, it didn&#8217;t know the size of the image. It would reach the parse stage of the workflow have to return fetch stage of the workflow. To fix this, Netscape followed the same workflow, but put a marker in the fetch stage and kept going, and then later, when it got the image, it would paint it in. Essentially, the load didn&#8217;t get hung up on an image, it would build around it. Flow and Paint multiple times.<br />
2) Netscape 2 built on this by adding events, which cause a script to get executed. Creating a &#8216;Flow -> Paint -> Event -> Script&#8217; loop. Something all browsers still use today.</li>
<li>Q: What are the roles of &#8216;name&#8217; and &#8216;id&#8217; attributes in HTML tags? What is an appropriate use of both?<br />
A: &#8216;name&#8217; = Identifies values in form data, Identifies a window/frame. They are mostly used in forms and such<br />
&#8216;id&#8217; = Uniquely identifies an element. This can be used to gain access to an object for use with JS &amp; CSS.</li>
<li>Q: Which pointers does each node in the DOM tree typically have?<br />
A: child, sibling, parent.</li>
<li>Q: Given a node object from a DOM tree, how do we determine if it is a text node or a regular node?<br />
A: If you get a nodes nodeName, a Text node will return #text, a regular node will return something other that #text.</p>
<table>
<tr>
<td width="50%">Element</td>
<td width="50%">The tag name, eg. HTML</td>
</tr>
<tr>
<td>Attr</td>
<td>The attribute name, eg. id</td>
</tr>
<tr>
<td>Text</td>
<td>#text</td>
</tr>
<tr>
<td>CDATASection</td>
<td>#cdata-section</td>
</tr>
<tr>
<td>EntityReference</td>
<td>The name of the entity reference, eg. amp</td>
</tr>
<tr>
<td>Entity</td>
<td>The entity name, eg. &#038;</td>
</tr>
<tr>
<td>ProcessingInstruction</td>
<td>The target of the processing instruction, eg. xml-stylesheet</td>
</tr>
<tr>
<td>Comment</td>
<td>#comment</td>
</tr>
<tr>
<td>Document </td>
<td>#document</td>
</tr>
<tr>
<td>DocumentType</td>
<td>The name of the document type, eg. html</td>
</tr>
<tr>
<td>DocumentFragment</td>
<td>#document-fragment</td>
</tr>
<tr>
<td>Notation</td>
<td>The notation name</td>
</tr>
</table>
<p>or refer to this check node.nodeType for these:<br />
Node.ELEMENT_NODE == 1<br />
Node.ATTRIBUTE_NODE == 2<br />
Node.TEXT_NODE == 3<br />
Node.CDATA_SECTION_NODE == 4<br />
Node.ENTITY_REFERENCE_NODE == 5<br />
Node.ENTITY_NODE == 6<br />
Node.PROCESSING_INSTRUCTION_NODE == 7<br />
Node.COMMENT_NODE == 8<br />
Node.DOCUMENT_NODE == 9<br />
Node.DOCUMENT_TYPE_NODE == 10<br />
Node.DOCUMENT_FRAGMENT_NODE == 11<br />
Node.NOTATION_NODE == 12</p>
</li>
</ul>
<p>Homework:</p>
<ul class="p2pu">
<li>Q: 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).<br />
A: I had a real hard time putting this one together. I couldn&#8217;t think it all the way through the process, I actually poached the code from <a href='https://gist.github.com/835680' target='_blank'>Melipone Moody</a>. See my version in action <a href='/P2PU/HotJava/week4/homework-1.html' target='_blank'>here</a>.</p>
<pre>
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	alert (sum + " text nodes found");
}
countTextNodes()
</pre>
</li>
<li>Q: 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.<br />
A: Simply just built of the previous example and used innerHTML. See it in action <a href='/P2PU/HotJava/week4/homework-2.html' target='_blank'>here</a>.</p>
<pre>
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	var add_this_copy = (sum + " text nodes found");
	// alert(add_this_copy);
	document.getElementById('place_content_here').innerHTML = add_this_copy;

}
countTextNodes()
</pre>
</li>
<li>Q: 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.<br />
A: Again, building off the previous example&#8230; See it <a href='/P2PU/HotJava/week4/homework-3.html' target='_blank'>here</a>.</p>
<pre>
window.onload=function(){
	countTextNodes();
}
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	var add_this_copy = (sum + " text nodes found");
	// alert(add_this_copy);
	document.getElementById('place_content_here').innerHTML = add_this_copy;
	return add_this_copy;
}
function change_to_bold(){
	var current_text = document.getElementById('place_content_here').innerHTML;
	var current_text = '<strong>'+current_text+'</strong>';
	document.getElementById('place_content_here').innerHTML = current_text;
}
function change_to_normal(){
	var current_text = document.getElementById('place_content_here').lastChild.innerHTML;
	document.getElementById('place_content_here').innerHTML = current_text;
}
</pre>
</li>
</ul>
<p>#p2pu-Jan2011-javascript101</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/js101-week-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS101 &#8211; Week 2 Assignment &#8211; 2.6.11</title>
		<link>http://jasonlydon.com/bloggery/js101-week-2-assignment-2-6-11</link>
		<comments>http://jasonlydon.com/bloggery/js101-week-2-assignment-2-6-11#comments</comments>
		<pubDate>Wed, 09 Feb 2011 04:20:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[P2PU]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=331</guid>
		<description><![CDATA[First of all, when I think of reflections, I think of this ASSIGNMENT Watch this video Questions for reflection (please reflect on your blog and discuss in comments below): Douglas Crockford: &#34;The JavaScript Programming Language&#34;/2 of 4 @ Yahoo! Video 1. Why do languages provide the switch statement, when we can achieve the same thing [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, when I think of reflections, I think of this</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="384" height="283" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://widget.nbc.com/videos/nbcshort_at.swf?CXNID=1000004.10045NXC&#038;widID=4727a250e66f9723&#038;clipID=1251363&#038;showID=243&#038;configXML=http%3A%2F%2Fwww.nbc.com%2Fservice%2Fvideowidget%2Fparams%2FdmlkZW9faWQ9MTI1MTM2Mw%3D%3D%2F&#038;initXML=http://www.latenightwithjimmyfallon.com%2Fvideo%2Fepisodes%2Finit.xml?videoId=1251363"/><param name="bgcolor" value="#000000" /><param name="quality" value="high" /><embed src="http://widget.nbc.com/videos/nbcshort_at.swf?CXNID=1000004.10045NXC&#038;widID=4727a250e66f9723&#038;clipID=1251363&#038;showID=243&#038;configXML=http%3A%2F%2Fwww.nbc.com%2Fservice%2Fvideowidget%2Fparams%2FdmlkZW9faWQ9MTI1MTM2Mw%3D%3D%2F&#038;initXML=http://www.latenightwithjimmyfallon.com%2Fvideo%2Fepisodes%2Finit.xml?videoId=1251363" quality="high" bgcolor="#000000" width="384" height="283" allowFullScreen="true" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed></object></p>
<p>ASSIGNMENT</p>
<p>Watch this video<br />
Questions for reflection (please reflect on your blog and discuss in comments below):</p>
<div><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=1710553&#038;vid=111594&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111594_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=1710553&#038;vid=111594&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111594_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111594/1710553">Douglas Crockford: &quot;The JavaScript Programming Language&quot;/2 of 4</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></div>
<ul class="p2pu">
<li>1. Why do languages provide the switch statement, when we can achieve the same thing with multiple if&#8230; elseif statements? Show one example of how you might use the switch statement.<br />
A: To be honest, I haven&#8217;t found a good explanation for why &#8216;switch&#8217; was originally implemented (other than it is in C++), but I have found plenty of examples where it is praised as &#8220;simple to use, logical in syntax, and most importantly, many programmers swear by it&#8221;<a href="http://www.javascriptkit.com/javatutors/switch.shtml" class="superscript">1</a> . So there are plenty of examples for why it stuck around.<br />
Example:</p>
<pre>
switch (today){
      case"sunday":
            alert("You watch TV, it's Sunday");
            [break;]
      case"monday":
            alert("Who's got a case of the Mondays?");
            [break;]
      case"tuesday":
            alert("It's only Tuesday, STFU!");
            [break;]
      case"wednesday":
            alert("Humpday");
            [break;]
      case"thursday":
            alert("Tonight is the best night on NBC");
            [break;]
      case"friday":
            alert("Rally and peak at 9pm, bed by 11");
            [break;]
      case"saturday":
            alert("Saturday, it's a Saturday");
            [break;]
      default:
            alert("Your society has no word for today's name!");
            [break;]
}
</pre>
</li>
<li>2. What is encapsulation, and what do functions encapsulate?<br />
A: Encapsulation: &#8220;every class inherits the methods of its parent and only needs to define things it wishes to change&#8221; or &#8220;A Class defines only the characteristics of the Object, a method defines only how the method executes.&#8221;<a href="https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript#Encapsulation" class="superscript">2</a><br />
Functions encapsulate local variables.
</li>
<li>3. What is a pure function? Is the function show() provided in Eloquent Javascript a pure function?<br />
A: Pure functions are function that &#8220;have no memory or I/O side effects&#8221;<a href="http://en.wikipedia.org/wiki/Functional_programming#Pure_functions" class="superscript">3</a> Side effects mean &#8220;in addition to producing a value, it also modifies some state or has an observable interaction with calling functions or the outside world.&#8221;<a href="http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29" class="superscript">4</a> So basically a pure function is basic mathematics, 2 + 2 = 4, always. And no variables are affected<br />
I don&#8217;t think the show() is a pure function because it does the bidding of the function associated within it, therefore it does change variables and not do a basic math function.
</li>
<li>4. What do we mean when we say a variable in a function is shadowing a top level variable?<br />
A: A top level variable is a variable created outside functions that can be accessed by ALL functions. When a function calls a variable, it first looks for it locally (aka inside this function) and if not found it then looks outside the function to the top level variables. I guess it is a shadow because top level variables are out there and obvious, while a variable with the same name is hiding in the shadows of the function waiting to pounce when it is needed.
</li>
<li>5. A recursive function must have some sort of an end condition. Why would we get a &#8220;out of stack space&#8221; error message if a recursive function does not have an end condition?<br />
&#8220;To understand recursion you must first understand recursion&#8221;<a href="http://www.htmlgoodies.com/primers/jsp/article.php/3622321/Javascript-Basics-Part-12.htm" class="superscript">5</a><br />
A: A recursive function is a function that calls itself inside itself. Without an end statement, it would continue on forever. The &#8220;stack&#8221; is where the web browser stores the variables as it works thru functions, each browser has a limited amount of space, thus, if a function runs on forever and continues working thru variables, it will run out of space in the stack.
</li>
<li>6. Reflect about the difference between object inheritance and class inheritance<br />
A: Object inheritance allows you to basically make a copy of an object that you expand upon. Class inheritance means that you need to define a new class tat extends a previous class and then create objects of that class.<a href="http://gorlith.blogspot.com/2011/02/javascript101-week-2-reflections.html" class="superscript">6</a>
</li>
<li>7. What is object augmentation, and how do we do it?<br />
A: Object Augmentation: Take an existing object and add new stuff to it at anytime. To do it, simply assign it. The general pattern is myObject[name] = value;<br />Just do it!
</li>
<li>8. There is a way to add a method to String, such as any new String we create will have that augmented method (this is a bit different from object augmentation). How would you do this?<br />
A:</p>
<pre>
String.prototype.newMethod = function (foo, bar) {
    //put code for new String function here
}
</pre>
</li>
<li>9. What is garbage collection?<br />
A: According to the video, it&#8217;s &#8220;mark and sweep so cycles do get reclaimed&#8221;, which meant almost nothing to me, but the internets told me it is basically the &#8220;collector&#8221; flags each block of data or variable that the program can reach, it then deletes any blocks without flags because they are not being used.
</li>
<li>10. What is the difference between an array and an object?<br />
A: Array inherits from Object. Arrays have a length, and objects do not. The video recommends that you use objects when the names are arbitrary strings and use arrays when the names are sequential integers.
</li>
</ul>
<p>Exercises 3.1 &#8211; 3.2 from chapter 3</p>
<ul class="p2pu">
<li>3.1 &#8211; Write a function called absolute, which returns the absolute value of the number it is given as its argument. The absolute value of a negative number is the positive version of that same number, and the absolute value of a positive number (or zero) is that number itself.
<pre>
function absolute(arg){
   if (arg < 0 ){
      return -arg
   } else {
      return arg
   }
}
</pre>
<p>
I then used buttons to open alerts for different numbers<br />
See an example <a href="/P2PU/HotJava/track2/ex3-1.html">here</a>.</li>
<li>3.2 - Write a function greaterThan, which takes one argument, a number, and returns a function that represents a test. When this returned function is called with a single number as argument, it returns a boolean: true if the given number is greater than the number that was used to create the test function, and false otherwise.
<pre>
function greaterThan(x) {
   return function(y) {
      return y > x;
   };
}
var greaterThanTen = greaterThan(10);
alert(greaterThanTen(9));
</pre>
<p>
See it <a href="/P2PU/HotJava/track2/ex3-2.html">here</a></li>
</ul>
<p>#p2pu-Jan2011-javascript101</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/js101-week-2-assignment-2-6-11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

