<?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/" version="2.0"><channel><title>HTML5, CSS3, jQuery, AJAX and more discussed by kaidez</title> <link>http://kaidez.com</link> <description /> <lastBuildDate>Fri, 25 May 2012 13:01:44 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kaidez" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="kaidez" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>The kaidez JavaScript Conference Tour: Leg 1 – Fluent 2012/San Francisco</title><link>http://kaidez.com/fluent-2012/</link> <comments>http://kaidez.com/fluent-2012/#comments</comments> <pubDate>Fri, 25 May 2012 09:00:15 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Personal]]></category><guid isPermaLink="false">http://kaidez.com/?p=5934</guid> <description><![CDATA[I was hoping to attend at least one JavaScript conference this year&#8230;luckily, I&#8217;m going to two! First up is O&#8217;Reilly&#8217;s three-day Fluent Conference in San Francisco (with June&#8217;s TXJS 2012 in Austin being the second one). Conference dates are May &#8230; <a href="http://kaidez.com/fluent-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><a href="http://fluentconf.com/fluent2012"><img class="alignleft size-full wp-image-5971" src="http://kaidez.com/wp-content/uploads/2012/05/fluent.png" alt="Fluent Conference 2012" width="236" height="137" /></a>I was hoping to attend at least <em>one</em> JavaScript conference this year&#8230;luckily, I&#8217;m going to <em>two</em>! First up is O&#8217;Reilly&#8217;s three-day <a href="http://fluentconf.com/fluent2012">Fluent Conference in San Francisco</a> (with June&#8217;s <a href="http://2012.texasjavascript.com/">TXJS 2012</a> in Austin being the second one). Conference dates are May 29th through the 31st: premium training sessions on the first day, keynotes and public sessions during the other two days.</p><h2>My Goals</h2><p>Like I said in <a href="http://kaidez.com/learn-javascript-before-jquery/">my last post</a>, I&#8217;ve realized that I understand JavaScript a hell of a lot better than I give myself credit for. While I&#8217;m not a guru, I&#8217;m well past trying to figure out how it works. The time has come for me to understand the best case scenarios of &#8220;when &#8220;and &#8220;why&#8221; to use it, along with some top-notch implementation techniques.</p><p>Fluent&#8217;s first day training sessions and subsequent public ones should help me in meeting these goals&#8230;<a href="http://fluentconf.com/fluent2012/public/schedule/full/public">the full list of courses and sessions is here</a>.</p><h2>Premium Sessions I&#8217;ll Be Taking</h2><p>The premium training day offers a morning and an afternoon block of sessions, allowing attendees to pick one from each block.</p><p>Here&#8217;s <a href="http://fluentconf.com/fluent2012/public/schedule/grid/public/2012-05-29">the full list of premium training sessions</a>: I&#8217;ll be attending &#8220;<a href="http://fluentconf.com/fluent2012/public/schedule/detail/24654">Breaking HTML5 limits on mobile JavaScript</a>&#8221; with Maximiliano Firtman in the morning and &#8220;<a href="http://fluentconf.com/fluent2012/public/schedule/detail/24856">Writing robust Node.js applications</a>&#8221; with Tom Hughes-Croucher in the afternoon.</p><p>I&#8217;m a big fan of Maximiliano (AKA Max). He&#8217;s been developing for and writing about the mobile web well before the iPhone pushed it to critical mass so he knows his stuff. Plus, Max curates the excellent mobile web reference, <a href="http://mobilehtml5.org/">mobilehtml5.org</a>&#8230;should be a good session.</p><p>As for the Node course, I also mentioned in my last post that Node is starting to creep into the day job. I&#8217;m taking this session to better prepare myself in case I&#8217;m asked to support it.</p><h2>Free Sessions &amp; Keynotes</h2><p>Keynotes are short and will be coming from some of the big names in web development: <a href="http://brendaneich.com/">Brendan Eich</a>, <a href="http://lea.verou.me/">Lea Verou</a>, <a href="http://paulirish.com/">Paul Irish</a>, <a href="http://stevesouders.com/">Steve Souders</a> and many others.</p><p>Here are the sessions I&#8217;m plan on attend, all of which are subject to change:</p><h3>Wednesday Sessions</h3><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24881"><em>Q&amp;A with Brendan Eich</em> »</a><br /> He invented JavaScript which created an environment inside which <em>all</em> web developers can prosper and has earned respect as an elder in the developer community. I&#8217;m not thrilled about a specific political contribution that Eich made a few years back, but I have the chance to hear JavaScript&#8217;s inventor actually talk about JavaScript&#8230;<em>OK?!?!</em></p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24926"><em>High Performance Snippets</em> with Steve Souders »</a><br /> Souders is an expert in the field of creating efficient, high-performance code. HTML5 Boilerplate, its build script, YSlow and PageSpeed were created using many of the techniques he writes about on his blog and in his books.</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24713"><em>Jasmine: An Introduction</em> with Davis W. Frank »</a><br /> As implied earlier, I know how to write JavaScript, I just have to embed the best practices in my brain. Reviewing Jasmine, a behavior-driven development (BDD) framework for JavaScript testing is a good start.</p><p>There&#8217;s a SLIGHT chance that I&#8217;ll pass on this session and go to <a href="http://fluentconf.com/fluent2012/public/schedule/detail/24889">the Bootstrap one</a>&#8230;will probably be a last minute decision.</p><p>These next two sessions are also happening at the same time, meaning I&#8217;ll have to make a choice&#8230;</p><p>Choice 1:<br /> <a href="http://fluentconf.com/fluent2012/public/schedule/detail/24109"><em>What Modernizr Teaches Us About Design &amp; Development</em> with Faruk Ateş »</a><br /> Modernizr is a kick-ass feature detection library that appears in practically every web dev stack nowadays. The guy that created it talks about it.</p><p>Choice 2:<br /> <a href="http://fluentconf.com/fluent2012/public/schedule/detail/24929"><em>/Reg(exp){2}lained/: Demystifying Regular Expressions</em> with Lea Verou »</a><br /> It&#8217;s an opportunity to hear a well-known, well-respected web developer talk about something that many web developers ignore.</p><p>No idea what to do here&#8230;</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24440"><em>Maintainable JavaScript</em> with Nicholas Zakas »</a><br /> I want to write JavaScript at work, knowing I can document it well enough so that others can fix it while off on vacation and drunk on a beach. Factor in that I&#8217;m a Zakas fan and I&#8217;m definitely going to this session.</p><h3>Thursday Sessions</h3><p>Here&#8217;s another case of two great sessions happening at the same time&#8230;</p><p>Choice 1:<br /> <a href="http://fluentconf.com/fluent2012/public/schedule/detail/24877"><em>SpineJS &#8211; Moving State to the Client</em> with Alex MacCaw »</a><br /> I&#8217;ve peeked at JavaScript MVC frameworks like Spine and Backbone for a while but haven&#8217;t really used them. I may check this session out.</p><p>Choice 2:<br /> <a href="http://fluentconf.com/fluent2012/public/schedule/detail/24686"><em>Sharing Code Between Client and Server with Node.js</em> with Chris Powers »</a><br /> Again, I have the Node bug so this may be the session for me.</p><p>Since I&#8217;m already doing the Node premium session and I&#8217;ll be attending a Node session after this one, I&#8217;m leaning towards the Spine session here&#8230;not sure yet.</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24643"><em>How to Deploy a Node.js App to Production (And Not Get Fired)</em> with Sean Hess »</a><br /> All the Node I&#8217;ve done up to this point has been on my laptop running off of&nbsp;<em>localhost,&nbsp;</em>not a production site. Hoping to get a better understanding of production-based Node with this session.</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24474"><em>Hybrid Web-Mobile Applications with PhoneGap and jQuery Mobile</em> with Ryan Stewart »</a><br /> I don&#8217;t see myself using PhoneGap to create native mobile apps&#8230;not that I dislike PhoneGap, I&#8217;m just not a native app guy. But I am curious about how it works with jQuery Mobile. I think this session will be a &#8220;cool kids&#8221; one, which is absolutely fine with me.</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24600"><em>JS + HTML5 Video + Canvas = WOAH!</em> with Wes Bos »</a><br /> I was really pumped about HTML5 Video at one point, but severely lost interested in it. I have seen some cool demos on how it works with Canvas so I&#8217;ll check it out.</p><p><a href="http://fluentconf.com/fluent2012/public/schedule/detail/24706"><em>Ember.js: An MVC framework for ambitious web applications</em> with Bruce Williams »</a><br /> I&#8217;ve heard nothing but good things about Ember so I&#8217;ll be at this one.</p><h3>Follow Me While I&#8217;m There!!!</h3><p>As I did with <a href="http://kaidez.com/at-mix11/">MIX11</a>, I probably won&#8217;t live blog during Fluent but will be <a href="https://twitter.com/kaidez">tweeting it</a> against the <a href="https://twitter.com/#!/search/%23FluentConf">#FluentConf hash-tag</a>. Follow me there and let me know if you&#8217;re going!</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/fluent-2012/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>5 Reasons Why You Need To Learn To Use JavaScript Before jQuery</title><link>http://kaidez.com/learn-javascript-before-jquery/</link> <comments>http://kaidez.com/learn-javascript-before-jquery/#comments</comments> <pubDate>Tue, 15 May 2012 09:50:03 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Coding Best Practices]]></category><guid isPermaLink="false">http://kaidez.com/?p=5871</guid> <description><![CDATA[A project came up at work involving Node, the software system that allows JavaScript to run server-side instead of client-side. I wasn&#8217;t involved in the project but wanted to play with the code once it landed in production and wanted &#8230; <a href="http://kaidez.com/learn-javascript-before-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>A project came up at work involving <a href="http://nodejs.org/">Node</a>, the software system that allows JavaScript to run server-side instead of client-side. I wasn&#8217;t involved in the project but wanted to play with the code once it landed in production and wanted to be ready if ever asked to support it. So I set Node up on my Mac laptop, read parts of its documentation and found some beginning Node learning resources online.</p><p>Server-side code is definitely not my thing so Node has always made me nervous. I can talk about how it works in the abstract, but actually <em>using</em> it has intimidated me. I delayed learning Node until the last minute.</p><p>But as I started playing with Node, something funny happened: understanding it turned out to be easy!</p><p>I&#8217;m not saying that it was so easy that I&#8217;m now a Node guru. I had to grasp Node&#8217;s event loop, its handling of server modules and gain a basic understanding of the how servers work in general. And I still have more to learn.</p><p>But in terms of the JavaScript needed to run Node, I picked it up in about two days. Knowing some basic JS things, that functions are first class objects, that these functions can be passed, that callbacks are powerful; knowing all that made my Node learning process much easier than expected.</p><p>I suppose the point is, I don&#8217;t know all the answers to Node (and still don&#8217;t), but thanks to my JavaScript knowledge, I understand all the questions.</p><p>None of this would have happened had I not made a conscious decision a year-and-a-half ago to focus on getting better at JavaScript instead of mastering jQuery. I&#8217;m may not be a JavaScript ninja but I&#8217;m comfortable putting it on my resume, something I was unsure about 18 months ago.</p><p>I need to be clear about something before I go on: I AM NOT BAD-MOUTHING JQUERY!!!! jQuery is awesome! I think you should use it and don&#8217;t see myself doing any future web projects without it.</p><p>jQuery effectively deals with a lot of cross-browser JavaScript issues, making overall web development an easier process. Its power as a DOM selection engine is so strong, that it doesn&#8217;t make sense to <em>not</em> use it. Furthermore, jQuery lets developers write quality JavaScript faster, so a case can be made that a developer using jQuery is, at times, more productive than one that doesn&#8217;t. Also, key JavaScript things like adding data to objects and function parameters are what&#8217;s needed to make jQuery work, meaning you can pick up some key JS skills by writing JQ. And a web designer with no coding experience whose main job is to work in PhotoShop eight hours a day shouldn&#8217;t be faulted for using jQuery to whip out a quick effect. At least I don&#8217;t think so.</p><p>While learning jQuery has lots of positives, the focus of your learning should mostly be on JavaScript: doing so makes you a better developer.</p><p>Here&#8217;s the list:</p><h2>1. Because understanding JavaScript makes it easier to understand all the JavaScript-related stuff</h2><p>Already implied in this post but it bears a deeper examination. Let&#8217;s look at this list:</p><h3>What You Know After Learning <em>Just</em> jQuery</h3><ul><li><a href="http://jquery.com/">jQuery</a></li><li><a href="http://jqueryui.com/">jQuery UI</a></li><li><a href="http://jquerymobile.com/">jQuery Mobile</a></li></ul><p>And in terms of jQuery UI and jQuery Mobile, I&#8217;m being nice here. While you can apply raw JavaScript and jQuery to your UI and Mobile projects, setting UI and Mobile up is mostly done by adding attributes, IDs and classes to HTML elements.  Things are made easy, an excellent goal that the jQuery team has achieved above and beyond all expectations.</p><p>Now, let&#8217;s look at this list:</p><h3>What You Know After Learning JavaScript <em>Before</em> jQuery</h3><ul><li><a href="http://jquery.com/">jQuery</a></li><li><a href="http://jqueryui.com/">jQuery UI</a></li><li><a href="http://jquerymobile.com/">jQuery Mobile</a></li><li><a href="http://docs.jquery.com/Plugins/Authoring">How to create jQuery plugins</a></li><li><a href="http://nodejs.org/">Node.js</a></li><li><a href="http://howtonode.org/how-to-module">How to create Node.js modules</a></li><li><a href="http://modernizr.com/">Modernizr</a></li><li><a href="http://yepnopejs.com/">yepnope.js</a></li><li><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAscript 5</a></li><li><a href="http://dojotoolkit.org/">dojo</a></li><li><a href="http://script.aculo.us/">script.aculo.us</a></li><li><a href="http://www.prototypejs.org/">Prototype</a></li><li><a href="http://mootools.net/">MooTools</a></li><li><a href="http://spinejs.com/">Spine</a></li><li><a href="http://documentcloud.github.com/backbone/">Backbone</a></li><li><a href="http://www.json.org/">JSON</a></li><li><a href="http://jsonselect.org/#overview">JSONselect</a></li><li><a href="http://phonegap.com/">PhoneGap</a></li><li><a href="http://www.appcelerator.com/platform/titanium-sdk">Titanium</a></li><li><a href="https://developer.mozilla.org/en/HTML/Canvas">HTML5 Canvas API</a></li><li><a href="https://developer.mozilla.org/en/Using_geolocation">Geolocation API</a></li><li><a href="https://developer.mozilla.org/en/Using_web_workers">Web Workers API</a></li><li><a href="http://coffeescript.org/">CoffeeScript</a></li><li><a href="https://github.com/janl/mustache.js">mustache.js</a></li><li><a href="http://handlebarsjs.com/">Handlebars.js</a></li><li><a href="https://github.com/jquery/qunit">QUnit</a></li><li><a href="http://pivotal.github.com/jasmine/">Jasmine</a></li><li><a href="http://fitzgen.github.com/github-api/">github.js</a></li></ul><p>&#8230;you get the idea.</p><p>While some of these things are so well-documented that a six-year old can use them, most of them are documented in a way that assumes the reader has pre-existing JavaScript knowledge. Many of these things assume you understand that a main object is loaded into the global namespace (like the <code>jQuery</code> and <code>Modernizr</code> objects) and that these objects have methods (like jQuery&#8217;s <code>.ajax()</code> method and Modernizr&#8217;s <code>addThis()</code> method). Also, knowing how to work with closures and callbacks is key to using many of these scripts and frameworks to their fullest.</p><h2>2. Because understanding JavaScript makes it easier for you to learn object-oriented languages</h2><p>JavaScript is not a full-on object-oriented language, it&#8217;s a <a href="https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model#Class-based_vs._prototype-based_languages">prototype-based language</a> that can be made to act like an object-oriented language. However, what you learn in JavaScript can cascade down to other languages. Case in point: PHP associative arrays are easy to pick up once you know how JavaScript&#8217;s module pattern works. And JavaScript closures introduce the idea of private, public and protected variables&#8230;major building blocks of C#, C++, Java and ActionScript.</p><h2>3. Because there are many cases when using JavaScript is more efficient</h2><p>Remember: your jQuery code doesn&#8217;t hit the page until it accesses the jQuery object that&#8217;s loaded into the browser. Accessing the object does happen fast but it&#8217;s faster if you write JavaScript that hits the browser directly.</p><p>The most obvious example here is adding, removing and manipulating DOM elements with things like <code><a href="https://developer.mozilla.org/En/DOM/Node.cloneNode">cloneNode</a></code> and <a href="https://developer.mozilla.org/en/DOM/document.createDocumentFragment">document fragments</a>. jQuery can help with these things but browsers can do them natively and more efficiently.</p><h2>4. Because potential employers care more about your JavaScript knowledge than your jQuery knowledge</h2><p>Why? Well for starters, lots of customer projects are created using the stuff in the number 1&#8242;s second list above, allowing web shops to charge the customers at a premium cost. And a good JavaScripter can figure out many things on that list over time, making them a very valuable employee. Second, employers want employees that can figure out coding problems on their own. They want an employee that can fix a Spine error one minute and a JSON one the next.</p><h2>5. Because JavaScript is so popular right now, that many excellent, <em>free</em> beginning learning resources are now readily available</h2><p>I&#8217;ll toot my own horn here and mention my last post on <a href="http://kaidez.com/useful-javascript-books/">great JavaScript books for beginners</a> but you have to pay for those. Here are some great free ones, two of which are jQuery-related:</p><ul><li style="list-style-type:none;"><h3><a href="http://www.codecademy.com/">Codecademy</a> &raquo;</h3><p>Great for beginners. It starts you at the JavaScript basics, building you up to creating structured JavaScript applications. Most importantly, <a href="https://developer.mozilla.org/en-US/learn/javascript">Mozilla Developer Network lists Codecademy as an excellent introductory level learning resource</a>, which is a ringing endorsement.</li><li style="list-style-type:none;"><h3><a href="http://jqfundamentals.com/">jQuery Fundamentals &raquo;</a></h3><p>Written by <a href="http://rmurphey.com/"> Rebecca Murphey</a> who is, hands down, my favorite web developer right now. <em>jQuery Fundamentals</em> teaches you jQuery the right way: by teaching you the JavaScript basics and best practices first.</li><li style="list-style-type:none;"><h3><a href="http://www.youtube.com/watch?v=i_qE1iAmjFg">10 Things I Learned from the jQuery Source &raquo;</a></h3><p>Paul Irish walks you through the core JavaScript code behind the jQuery library, highlighting things like anonymous functions, robust module patterns and why they were written the way they were written.</li></ul><p>Think I left some reasons or resources out? Feel free to comment. AND NO SPAM!! I know what it looks like.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/learn-javascript-before-jquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>5 Useful JavaScript Books</title><link>http://kaidez.com/useful-javascript-books/</link> <comments>http://kaidez.com/useful-javascript-books/#comments</comments> <pubDate>Fri, 30 Mar 2012 09:50:50 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Books]]></category><guid isPermaLink="false">http://kaidez.com/?p=5804</guid> <description><![CDATA[Disclaimer: because of my affiliate relationships, you will make me money if you click on any of the book links below, then buy a book. The good news is, there are a lot of JavaScript learning resources online. The bad &#8230; <a href="http://kaidez.com/useful-javascript-books/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><em>Disclaimer: because of my affiliate relationships, you will make me money if you click on any of the book links below, then buy a book.</em></p><p>The good news is, there are a lot of JavaScript learning resources online. The bad news is, there are a lot of JavaScript learning resources online. Filtering the bad ones out from the good ones is hard.</p><p>This is why whenever I try to learn a new computer skill, I&#8217;ll buy a book about it first. Books go through rigid editing processes like fact checking and proofreading, all helping to filter out the bad content.</p><p>I have a <a href="http://www.lynda.com/home/otl.aspx?utm_medium=affiliate&#038;utm_source=ldc_affiliate&#038;utm_content=329&#038;utm_campaign=CD2146&#038;bid=329&#038;aid=CD2146&#038;opt=">lynda.com</a> account so lately, I&#8217;ve used that as learning resource more than books. But JavaScript is the exception: a lot of great books have come out in the past few years, many of them &#8220;thinking books&#8221; that seemingly use theory when talking about JS.</p><p>Some books are better than others. I&#8217;ve read <em>a lot</em> of JavaScript books in the year before this article&#8217;s publish date. So as far as <em>those</em> books go, I&#8217;ve created a list of JS books which, I think, helps with the filtering process and lists only the best ones&#8230;so far. Here they are:</p><h2><a href="http://www.amazon.com/gp/product/0321772970/ref=as_li_qf_sp_asin_tl?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0321772970">1. <em>JavaScript: Visual QuickStart Guide (8th Edition)</em> by Dori Smith &amp; Tom Negrino</a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0321772970" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h2><p><a href="http://www.amazon.com/gp/product/0321772970/ref=as_li_qf_sp_asin_il?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0321772970"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=0321772970&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=kaidez-20&#038;ServiceVersion=20070822" align="left" style="padding:0 10px 10px 0;"></a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0321772970" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />The best book for the JavaScript newbie. Every new edition migrates with the JavaScript trends: from image rollovers and cookie baking to DOM scripting to AJAX to object literals. The 8th addition keeps the tradition.</p><p>While the book does cover the trends, it also provides detailed step-by-step instructions on things that the JavaScript beginner needs to know: what a variable is, how to create an array, why are external JS files the right way to go, and so on. And it moves on from the basics to tutorials on more advanced topics such as reading data from a web server with AJAX and a few jQuery techniques. It ends with a great list of other learning resources in its &#8220;Where to Learn More&#8221; appendix.</p><p>If you know <em>absolutely nothing</em> about JavaScript and you pick this book up, I suggest that you treat it like a textbook. It covers JavaScript in the broadest sense, explaining the &#8220;hows&#8221; and &#8220;whys&#8221; of the code samples.</p><p>Personally, I think <em>Visual QuickStart Guide</em> should spend a bit more time covering the things that make JavaScript act more like an object-oriented programming language. One of its tutorials does mentions JSON, but not in great detail. Its object chapter does cover advance DOM manipulation techniques like <code>cloneNode()</code>, but aside from the object literal, there no mention of design patterns.</p><p>A beginner&#8217;s JS book doesn&#8217;t need to cover every single thing about objects, but should leave the reader with a basic understanding of JavaScript&#8217;s OOP potential. The book doesn&#8217;t fail at this, but doesn&#8217;t exactly hit a home run here.</p><p>Regardless of its limited coverage of JavaScript&#8217;s OOP possibilities, <em>Visual QuickStart Guide</em> is still the first book I recommend to someone who wants to learn JavaScript, but knows absolutely nothing about it.</p><h2><a href="http://www.amazon.com/gp/product/1847194141/ref=as_li_tf_tl?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1847194141">2. <em>Object-Oriented JavaScript</em> by Stoyan Stefanov</a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=1847194141" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h2><p><a href="http://www.amazon.com/gp/product/1847194141/ref=as_li_tf_il?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1847194141"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=1847194141&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=kaidez-20&#038;ServiceVersion=20070822" align="left" style="padding:0 10px 10px 0"></a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=1847194141" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />I&#8217;ll get straight to the point: this is an <em>excellent</em> book!</p><p>Embellishing a bit more, Yahoo developer Stefanov does an awesome job of teaching the reader how to treat JavaScript as a full-on object-oriented language. He also does an awesome job of explaining the &#8220;hows&#8221; and &#8220;whys&#8221; job of the code exercises.</p><p><em>OOJ</em> does cover JavaScript basics like variables and arrays, but not as in-depth as <em>Visual QuickStart Guide</em>. And it doesn&#8217;t matter because every topic he discusses, inheritance, closures, prototypes, getters, setters-all of it is useful in today&#8217;s JavaScript environment and are discussed in-depth.</p><p>A few things: <em>OOJ</em> was published by Packt Publishing who is notorious for releasing books with grammatical and spelling errors-this book is no exception. If you buy it, go to <a href="http://www.packtpub.com/support">Packt&#8217;s Support page</a>, click on the &#8220;Title&#8221; drop-down menu and find the book title: you&#8217;ll see the errors.</p><p>Also, <a href="http://www.phpied.com/publishing-5-books-this-year/">Stefanov is working on the 2nd Edition of this book.</a> He&#8217;ll be tackling ECMAScript5 and will have a new chapter on JS testing and documentation.</p><p>Despite the spelling errors and imminent updated version, any beginning developer with a little-better-than basic understanding of JS <em>has</em> to read the first edition of <em>Object-Oriented JavaScript</em>. That&#8217;s it&#8230;no more, no less.</p><h2><a href="http://www.amazon.com/gp/product/0596806752/ref=as_li_tf_tl?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596806752">3. <em>JavaScript Patterns</em> by Stoyan Stefanov</a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0596806752" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h2><p><a href="http://www.amazon.com/gp/product/0596806752/ref=as_li_tf_il?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596806752"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=0596806752&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=kaidez-20&#038;ServiceVersion=20070822" align="left" style="padding:0 10px 10px 0"></a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0596806752" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />Another Stoyan Stefanov book, this one explains some excellent best practices such as the right way to structure for loops, when to use <code>hasOwnProperty</code>, and yes, proper JavaScript patterns. Stefanov did apply a few of these best practices in his <em>OOJ</em> coding samples but in <em>Patterns</em>, he explains the meaning behind them.</p><p>This book also drives home the importance of keeping the global space as clean as possible. Stefanov&#8217;s tips on namespacing patterns, inheritance and encapsulation are must-learns.</p><p>This is not a book for beginners and the author says so in the Preface. Except for the first two chapters, reading this book without frustration requires an intermediate understanding of JavaScript, particularly objects.</p><h2><a href="http://www.amazon.com/gp/product/0596517742/ref=as_li_tf_tl?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596517742">4. <em>JavaScript: The Good Parts</em> by Douglas Crockford</a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0596517742" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h2><p><a href="http://www.amazon.com/gp/product/0596517742/ref=as_li_qf_sp_asin_il?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596517742"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=0596517742&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=kaidez-20&#038;ServiceVersion=20070822" align="left" style="padding:0 10px 10px 0"></a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=0596517742" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />This article is slightly implying that <em>Object-Oriented JavaScript</em> is the best JavaScript book, which is subjective to other&#8217;s opinions. But no one can deny that <em>JavaScript: The Good Parts</em> is the most important book.</p><p>Written by Douglas Crockford, the creator of JSON who also works at Yahoo, this book has had tremendous influence on the JavaScript community since it&#8217;s 2008 publication.  Dig thru the core files of jQuery and Modernizr and you&#8217;ll see that they&#8217;re chocked full of best practices mentioned in the <em>The Good Parts</em> or, as many refer to it, &#8220;the Crockford Book.&#8221;</p><p>Many, many things that you first learn in JavaScript will need to be unlearned after reading <em>The Good Parts</em>. Iterators, the <code>new</code> keyword, switch/case statements&#8230;be prepared to throw some of these away.</p><p>As with <em>JavaScript Patterns</em>, the Crockford book is not for beginners&#8230;REALLY not for beginners. Those that can&#8217;t do anything dynamic with JS outside of making a few alerts will find this book a tough read.</p><h2><a href="http://www.amazon.com/gp/product/1590597273/ref=as_li_tf_tl?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1590597273">5. <em>Pro JavaScript Techniques</em> by John Resig</a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=1590597273" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></h2><p><a href="http://www.amazon.com/gp/product/1590597273/ref=as_li_tf_il?ie=UTF8&#038;tag=kaidez-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=1590597273"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;Format=_SL160_&#038;ASIN=1590597273&#038;MarketPlace=US&#038;ID=AsinImage&#038;WS=1&#038;tag=kaidez-20&#038;ServiceVersion=20070822" align="left" style="padding:0 10px 10px 0"></a><img src="http://www.assoc-amazon.com/e/ir?t=kaidez-20&#038;l=as2&#038;o=1&#038;a=1590597273" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />I&#8217;ll be completely upfront here: I&#8217;ve read most of this book, but not all of it. Plus, I haven&#8217;t implemented a lot of the new stuff I learned from it.</p><p>But this first book by jQuery creator John Resig stands out because it takes key JavaScript concepts, like AJAX and DOM manipulation, and expands on them with step-by-step exercises. It also covers JavaScript testing which is Resig&#8217;s most underrated skill.</p><p><em>Techniques</em> isn&#8217;t as difficult a read as <em>JavaScript Patterns</em> or the Crockford book, but it won&#8217;t explain what a variable is like <em>Visual QuickStart Guide</em> will. But the fact that it offers detailed tutorials on important JS stuff makes it a must-read.</p><h2>A suggestion on how to read these books</h2><p>If you understand variables, arrays, functions, try/catch statements and for loops in JavaScript, you MIGHT want to skip <em>Visual QuickStart Guide</em> and go straight to <em>Object-Oriented JavaScript</em>. And as mentioned above, some of the best practices discussed in both <em>JavaScript Patterns</em> and the Crockford Book are discussed in the <em>OOJ</em> book, but none of the others.</p><p>To be honest, I suggest that you read <em>Patterns</em> and <em>The Good Parts</em> in parallel with the first two books. For example: when you start to read about for loops in <em>Visual QuickStart Guide</em>, take a few minutes and see what both <em>Patterns</em> and the Crockford book say about them. This is a pain, but the sooner you learn these best practices, the better.</p><p>After all this, go back and read <em>Patterns</em> and the Crockford book in full.</p><p>Happy reading!</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/useful-javascript-books/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>TUTORIAL: What NYC Subways Can Teach Us About JavaScript Closures</title><link>http://kaidez.com/javascript-closures-tutorial/</link> <comments>http://kaidez.com/javascript-closures-tutorial/#comments</comments> <pubDate>Tue, 27 Mar 2012 09:50:41 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Tutorials]]></category><guid isPermaLink="false">http://kaidez.com/?p=5604</guid> <description><![CDATA[VIEW THE DEMO FIRST &#187; JavaScript doesn&#8217;t fit the strict definition of an object-oriented programming language, but it fits well enough so that you can use it to do object-oriented stuff. Closures play a big role here so understanding how &#8230; <a href="http://kaidez.com/javascript-closures-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><a href="http://jsfiddle.net/kaidez/KypGQ/" target="blank">VIEW THE DEMO FIRST &raquo;</a></p><p>JavaScript doesn&#8217;t fit the strict definition of an object-oriented programming language, but it fits well enough so that you can use it to do object-oriented stuff. Closures play a big role here so understanding how they work is important.</p><h2>Encapsulation</h2><p>First, understand a programming concept called <em>encapsulation</em> and understand that it has two roles:</p><ul><li style="list-style-type:decimal; padding-bottom: 13px;">Encapsulation hides your code from the web browser&#8217;s global space until the global space actually needs it, a top-notch JavaScript best practice.</li><li style="list-style-type:decimal;">It organizes your code quite nicely.</li></ul><p>You encapsulate variables and functions for the most part, and do so by placing them inside another function. Encapsulated variables are called <em>private variables</em> while encapsulated functions are called <em>methods</em>.</p><p>A private variable is not directly visible by the world outside of the encapsulating function. Encapsulated methods, however, act a little differently:</p><ul><li style="padding-bottom:13px;">An encapsulated method that returns something is called <em>public method</em> because whatever it returns, it returns to the global space. This means that other parts of your code can access it <em>if you tell your code to do so</em>.</li><li style="padding-bottom:13px;">A public method is also a <em>privileged method</em>. This is because it has &#8220;privileged&#8221; access to any variables and methods that it&#8217;s encapsulated with.</li><li>An encapsulated method can also be a <em>private method</em> <del datetime="2012-04-10T19:22:01+00:00">if it doesn&#8217;t return anything</del> that doesn&#8217;t return a specific value we give it (meaning that it will still return <code>undefined</code>). Despite this, always remember that it&#8217;s doing something&#8230;that&#8217;s the point of functions, isn&#8217;t it? Maybe it&#8217;s doing something as simple as sending out an alert, but it&#8217;s doing <em>something</em>. And if it&#8217;s encapsulated with a public method, the public method can take whatever the private method is doing and send out to the global space.</li></ul><p>The stricter object-oriented languages like C# and Java have syntax to create private, public and privileged code, but JavaScript does not. JavaScript can still create such code, and it can still be accessed if it&#8217;s private.</p><p><em>In JavaScript, accessing private, encapsulated code from the outside is done with closures.</em></p><p>Obviously, closures can be tough to understand at first, but understanding them is a must if you want to master JavaScript. So, I&#8217;m going to try to help here.</p><p>A little parable about the New York City subway may help&#8230;</p><h2>The Subway Story</h2><p>Of all the subway systems in the world, New York City&#8217;s is the most famous. It averages 10 million rides a week and is made up of 421 subway stations.</p><p>The NYC subway has 24 lines, each traveling through four of the city&#8217;s five boroughs: Manhattan, Brooklyn, Queens and the Bronx (sorry Staten Island). So for example: the L line travels from 8th Avenue in Manhattan to Canarsie in Brooklyn, the 6 train travels from Pelham Bay Park in the Bronx to Manhattan&#8217;s Wall Street neighborhood, and so on.</p><p>There is no borough that all of these lines run through: every borough has a line that doesn&#8217;t run through it. And in the case of Manhattan, the busiest borough, that line is the G line that, as of this article, runs from Long Island City in Queens to the Kensington neighborhood in Brooklyn.</p><p>The only way to get to &#8220;the G&#8221; from Manhattan is to take another subway line to a connecting station where the G stops, then transfer over. The G has many connecting stations that you can get to from Manhattan. A few options are:</p><ul><li style="padding-bottom:13px;">Someone catching the E train at its 14th Street Manhattan stop can take it to its Court Square Queens stop and catch the G.</li><li style="padding-bottom:13px;">Someone catching the F train at its 2nd Avenue Manhattan stop can take it its to Fort Hamilton Parkway Brooklyn stop and catch the G.</li><li>Someone catching the N train at its 34th Street Manhattan stop can take it to its 4th Avenue Brooklyn stop and catch the G.</li></ul><p>A more direct line between Manhattan and the neighborhoods that the G runs along would be great, but impossible. Strictly speaking, Manhattan can&#8217;t see the G line so it can&#8217;t access it directly.</p><h2>The Simple Subway Closure Examples</h2><p>Now&#8230;how does all of this subway stuff tie in with closures?</p><ul><li style="padding-bottom:13px;">Think of the G line as a private variable encapsulated by a function named <code>brooklyn</code>.</li><li style="padding-bottom:13px;">All those stops along the G, like Court Square? Think of them as both public and privileged methods: they&#8217;re public because things outside of the <code>brooklyn</code> function can access them, but they&#8217;re also privileged because they&#8217;re inside the <code>brooklyn</code> function and have access to the private variable, the G line.</li><li>Since the only way to get to the G is via one the connecting lines, think of the connecting lines as closures.</li></ul><p>Let&#8217;s start with small examples that will build up to the big one. I&#8217;ll be running these simple examples in Firebug Console for Firefox.</p><p><strong><em>IMPORTANT: Every time you run a new block of code in the Console, you must do it in a new browser tab.</em></strong></p><p>Cut-and-paste the code below in to the Console and run it:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> GLine <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;You have connected to the G line!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>GLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//alert popup appears!</span></pre></div></div><p>All works fine&#8230;we get an alert popup that says &#8220;You have connected to the G line!&#8221;</p><p>Now, <strong>open up a new tab</strong> and plug this code in the console and run it:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> GLine <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;You have connected to the G line!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>GLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//Oops! The alert doesn't show!</span></pre></div></div><p>The console now returns a message that the <code>GLine</code> is not defined.  This because <code>GLine</code> is now a private variable wrapped inside the <code>brooklyn</code> function, meaning the outside world can&#8217;t see it. And since our alert lives in the outside world, it&#8217;s giving us this error.</p><p>A closure named <code>connectingLine</code> can help us here. <strong>Open up a new tab again</strong> and run this code in the console:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> GLine <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;You have connected to the G line!&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>GLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> connectingLine <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connectingLine<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//alert popup appears!</span></pre></div></div><p>And with that, the alert now pops up&#8230;let&#8217;s break down why:</p><p>The <code>brooklyn</code> function now contains the not only the <code>GLine</code> private variable, but also an inner function. This inner function is a public method that&#8217;s also a privileged method.</p><p>As a public method, the function returns whatever it does to the world outside of <code>brooklyn</code>, which is our alert from the earlier examples.  And as a privileged method, the function has access to the <code>GLine</code> private variable that it&#8217;s encapsulated with, which is the alert message.</p><p>Our closure, <code>connectingLine</code>, has the power to find what the public/privileged method returns to the world outside of <code>brooklyn</code>. And again, what it returns is an alert that displays the value of <code>GLine</code>.</p><h2>The Difficult Subway Closure Example</h2><p>We started with alerts for the sake of easy explanation-now let&#8217;s create something more complicated with a private method:</p><h3>HTML for the difficult closure example</h3><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>The NYC subway can teach you about closures!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;eTrain&quot;</span>&gt;</span>Catch the G train by taking the E Train<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fTrain&quot;</span>&gt;</span>Catch the G train by taking the F Train<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nTrain&quot;</span>&gt;</span>Catch the G train by taking the N Train<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;myRoute&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.7.2.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;scripts.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div><p>Our simple HTML5-formatted page has three links, each with unique page ID. Using jQuery (note the jQuery core library is attached), our links will run the our JavaScript when clicked. Our JavaScript code will go in the <code>scripts.js</code> file.</p><h3>JavaScript for the difficult closure example (scripts.js)</h3><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> brooklyn<span style="color: #339933;">,</span>
 connectWithETrain<span style="color: #339933;">,</span>
 connectWithFTrain<span style="color: #339933;">,</span>
 connectWithNTrain<span style="color: #339933;">;</span>
&nbsp;
brooklyn <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> GLine <span style="color: #339933;">=</span> <span style="color: #3366CC;">'G line!'</span><span style="color: #339933;">;</span>
 <span style="color: #003366; font-weight: bold;">function</span> howToGetThere<span style="color: #009900;">&#40;</span>trainLine<span style="color: #339933;">,</span>startingStation<span style="color: #339933;">,</span>endingStation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myRoute'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Catch the '</span> <span style="color: #339933;">+</span> trainLine <span style="color: #339933;">+</span> <span style="color: #3366CC;">' at the '</span> <span style="color: #339933;">+</span> startingStation <span style="color: #339933;">+</span> <span style="color: #3366CC;">' station. Take it to '</span> <span style="color: #339933;">+</span> endingStation <span style="color: #339933;">+</span> <span style="color: #3366CC;">' station and get off to catch the '</span> <span style="color: #339933;">+</span> GLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
    ETrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'E train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'14th Street, Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Court Square'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    FTrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'F train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'2nd Avenue Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Fort Hamilton Parkway'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    NTrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'N train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'34th Street Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'4th Avenue'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
connectWithETrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connectWithFTrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connectWithNTrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#eTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithETrain.<span style="color: #660066;">ETrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithFTrain.<span style="color: #660066;">FTrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithNTrain.<span style="color: #660066;">NTrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Let&#8217;s break this code down:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>This is a lot of code and we don&#8217;t want it in the global space as that can screw things up, so we&#8217;re wrapping it in a <em>self-executing anonymous function</em> (it has other names, but I like this one).</p><p>This means that we wrap all this code up in an unnamed function: note that there&#8217;s no name between <code>function</code> and <code>()</code> on the first line. The code ends with another <code>()</code> on the last line which makes the function run, or &#8220;self-execute.&#8221;</p><p>And a little piece of trivia: the code for the jQuery core library is wrapped up in a self-executing anonymous function. This type of function has been around for a while, but jQuery&#8217;s usage of it has increased its popularity with developers.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> brooklyn<span style="color: #339933;">,</span>
 connectWithETrain<span style="color: #339933;">,</span>
 connectWithFTrain<span style="color: #339933;">,</span>
 connectWithNTrain<span style="color: #339933;">;</span></pre></div></div><p>These are variables that we&#8217;re going to use at some point in our code.  We&#8217;re naming them but not initializing them by giving them a value (although you should if possible).</p><p>We&#8217;re creating them using the <em>single var pattern</em>, meaning that we group all of our variables together with one <code>var</code> keyword and comma-separate them.  This keeps our variables organized and easy to find, and since <strong><em>JavaScript moves variables to the top of functions anyway</em></strong>, we might as well do it ourselves.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">brooklyn <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div><p>Our <code>brooklyn</code> function has returned&#8230;only this time, it&#8217;s not a function. Remember, we declared it as a variable in the beginning.</p><p>This <code>brooklyn</code> variable is now equal to another anonymous function that encapsulates a lot of code.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">var</span> GLine <span style="color: #339933;">=</span> <span style="color: #3366CC;">'G line!'</span><span style="color: #339933;">;</span>
 <span style="color: #003366; font-weight: bold;">function</span> howToGetThere<span style="color: #009900;">&#40;</span>trainLine<span style="color: #339933;">,</span>startingStation<span style="color: #339933;">,</span>endingStation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myRoute'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Catch the '</span> <span style="color: #339933;">+</span> trainLine <span style="color: #339933;">+</span> <span style="color: #3366CC;">' at the '</span> <span style="color: #339933;">+</span> startingStation <span style="color: #339933;">+</span> <span style="color: #3366CC;">' station. Take it to '</span> <span style="color: #339933;">+</span> endingStation <span style="color: #339933;">+</span> <span style="color: #3366CC;">' station and get off to catch the '</span> <span style="color: #339933;">+</span> GLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div><p>Our <code>GLine</code> private variable is still here and it&#8217;s still a text string, but it&#8217;s shorter than the earlier versions. <code>GLine</code> is joined by a private method called <code>howToGetThere()</code>.</p><p>A reminder: a private method is method <del datetime="2012-04-10T19:25:16+00:00">that doesn&#8217;t return anything</del> that returns no other value than <code>undefined</code> but does something.  And as we can see, this describes <code>howToGetThere()</code> perfectly.</p><p>And what&#8217;s <code>howToGetThere()</code> &#8220;doing?&#8221; It&#8217;s using jQuery to look for the <code>myRoute</code> ID on our HTML page, then load a text string into it with the jQuery&#8217;s <code>.html()</code> function (<em>FYI: <code>.html()</code> is actually a jQuery method!</em>)</p><p>The <code>howToGetThere</code> method also has parameters that will be passed into the text string: <code>trainLine</code>, <code>startingStation</code> and <code>endingStation</code>. They will represent, respectively, the name of the train line to catch, where in Manhattan to catch it and where to get off to catch the G Line. The <code>GLine</code> variable will be passed to the text string as well.</p><p>The <code>howToGetThere</code> private method is going to run when a link is clicked, but we have a few more things to do first, code-wise.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
  ETrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'E train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'14th Street, Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Court Square'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  FTrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'F train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'2nd Avenue Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Fort Hamilton Parkway'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  NTrain<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    howToGetThere<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'N train'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'34th Street Manhattan'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'4th Avenue'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Here are three public methods: <code>ETrain</code>, <code>FTrain</code> and <code>NTrain</code>. They all have access to the <code>howToGetThere</code> private method and are written out using something called the <em><a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript">module pattern</a></em>.</p><p>Each of these methods runs the <code>howToGetThere</code> private method, returning the parameters we discussed earlier. Again, <code>howToGetThere</code> will run when a page link is clicked but before we talk about that, we have to set up our closures first.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">connectWithETrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connectWithFTrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
connectWithNTrain <span style="color: #339933;">=</span> brooklyn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Here are the closures. They&#8217;re actually the variable names we created at the top of our code with the single var pattern-we&#8217;ve just now given them a value.</p><p>The value of each closure is the <code>brooklyn()</code> function, meaning it can access the public methods. It will do this with links, which we&#8217;ll now set up.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#eTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithETrain.<span style="color: #660066;">ETrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#fTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithFTrain.<span style="color: #660066;">FTrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nTrain'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> connectWithNTrain.<span style="color: #660066;">NTrain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Every time one of our three page links is clicked, jQuery&#8217;s <code>.click()</code> method runs a callback function. This function then runs one of our three public methods, which in turn, runs the <code>howToGetThere()</code> private method.</p><p>This means that a text string will load into the <code>myRoute</code> page ID when a link is clicked. The parameters defined with the public methods decide what the text string will say.</p><p>That&#8217;s it for the code. I hope it helps but am sure you want to read up more on the subject. These articles may help.</p><h2>Further Reading</h2><h3><a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures">MDN Closure Article &raquo;</a></h3><p>The Mozilla Developer Network&#8217;s excellent post on closures is your first stop. Take note of the potential performance issues mentioned at the end.</p><h3><a href="http://howtonode.org/why-use-closure"><em>Why use &#8220;closure&#8221;?</em> by Tim Caswell &raquo;</a></h3><p>Another excellent article by this California-based developer. His closure examples also use factory patterns and <code>Object.prototype</code>.</p><h3><a href="http://vimeo.com/1967261">Stuart Langridge: Secrets of JavaScript Closures (video) &raquo;</a></h3><p>Hilarious presentation from this UK-based developer.</p><h3><a href="http://www.manning.com/free/excerpt_resig.html">Excerpt from John Resig&#8217;s Upcoming Book, <em>Secrets of the JavaScript Ninja</em> &raquo;</a></h3><p>jQuery creator John Resig has written extensively on JavaScript closures. This sample content about closures from his upcoming book is, I think, his most in-depth article on the subject. It&#8217;s probably the toughest read on this list, but a great read nonetheless. Registration is required.</p><h2>Conclusion</h2><p>Closures are tough to understand in the beginning, I don&#8217;t deny it. But they&#8217;re useful as hell and make your JavaScript super-efficient. Re-read this article if you need to, check out the articles on the reading list and hit me up if you have questions.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/javascript-closures-tutorial/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>A Simple Explanation of HTML5</title><link>http://kaidez.com/simple-html5-explanation/</link> <comments>http://kaidez.com/simple-html5-explanation/#comments</comments> <pubDate>Fri, 09 Mar 2012 09:50:36 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[HTML5]]></category><guid isPermaLink="false">http://kaidez.com/?p=5329</guid> <description><![CDATA[HTML5 is big news right now. Web developers have been developing sites with it for the past few years, but awareness among the business community and the general public is really just starting up. This is great! HTML5 is a &#8230; <a href="http://kaidez.com/simple-html5-explanation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>HTML5 is big news right now. Web developers have been developing sites with it for the past few years, but awareness among the business community and the general public is really just starting up.</p><p>This is great! HTML5 is a major step forward in web development. Plus, HTML5 highlights some excellent coding standards that have been around for years, but aren&#8217;t as widely practiced as they should be.</p><p>As awesome as this is, I&#8217;ve had a few conversations with non-developers who think HTML5 is a magic bullet. Most talk about it as something that they <em>should</em> be doing without fully understanding <em>what it actually is</em>.<br /> <img src="http://kaidez.com/wp-content/uploads/2012/03/HTML5_Logo.png" style="padding:10px 0;" alt="HTML5 Logo" align="right"/><br /> While some web developers may be frustrated by the misunderstanding, part of their job is to explain to clients and employers what&#8217;s good and bad about new technologies, and without a lot of tech terms. So I&#8217;m going to take a stab at providing a simple HTML5 explanation.</p><p>And for the record: I think we should be using HTML5 when creating sites, but only in a way that helps us carry through our content strategy.</p><p>Here are the topics for this article:</p><ul style="margin-bottom:0px;"><li style="padding-bottom:13px;"><a href="#What-Is-HTML5">What Is HTML5 <em>Exactly</em>?</a></li><li style="padding-bottom:13px;"><a href="#Where-Did-HTML5-Come-From">Where Did HTML5 Come From?</a></li><li style="padding-bottom:13px;"><a href="#Semantic-Markup">Semantic Markup</a></li><li style="padding-bottom:13px;"><a href="#Web-Applications">Web Applications</a></li><li style="padding-bottom:13px;"><a href="#Mobile-Web-Development">Mobile Web Development</a></li><li style="padding-bottom:13px;"><a href="#Making-The-Site-Look-Pretty">Making The Site Look Pretty</a></li><li style="padding-bottom:13px;"><a href="#How-Is-HTML5-Being-Used-As-of-This-Article">How Is HTML5 Being Used As of This Article?</a></li><li style="padding-bottom:13px;"><a href="#How-Can-Businesses-Use-HTML5-TML5-Related-Technologies-Right-Now">How Can Businesses Use HTML5 &#038; HTML5 Related-Technologies Right Now?</a></li></ul><h3><a id="What-Is-HTML5">What Is HTML5 <em>Exactly</em>?</a></h3><p>The 25-word answer is:<div style="margin:0px auto; text-align:center; width: 650px; font-style:italic; padding:5px 0 25px 0;"><strong><em>&#8220;HTML5 is a major update to HTML that brings excellent new features to both websites and web applications, but also highlights an important older feature.&#8221;</em></strong></div><p>Expanding on this definition, the four key things to know about HTML5 are:</p><ul><li>it creates better <em>semantic markup</em> (the important older feature).</li><li>it allows for the creation of more robust <em>web applications.</em></li><li>it allows for top-notch <em>mobile web development.</em></li><li>creating websites and web applications with HTML5 is a best practice but, in all honesty, not a requirement.</li></ul><h3><a id="Where-Did-HTML5-Come-From">Where Did HTML5 Come From?</a></h3><p>Created in 1990, HTML has always been a programming language that creates a website&#8217;s basic structure.  To build a website, HTML &#8220;frames&#8221; it first, then things like copy and images are added to complete the job.</p><p>HTML updates are overseen by the <a href="http://www.w3.org/">World Wide Web Consortium</a>, or, the W3C. When they began work on the next update in 2004, a group of outside companies spoke out against the direction the W3C was taking it.</p><p>The update was great for <em>websites</em>, the companies said, but not so great for the new <em>web applications</em> that were starting to appear.  Also, the W3C&#8217;s suggested update wasn&#8217;t backwards-compatible with older versions of HTML, which would cause developers a ton of problems.</p><p>The companies felt that the W3C weren&#8217;t evolving HTML beyond a structural language, so they formed a separate group called the <a href="http://www.whatwg.org/">Web Hypertext Application Technology Working Group</a>, or WHATWG (pronounced &#8220;what-wig&#8221;) to do just that.  Their goal was to build a new HTML that worked well for both websites <em>and</em> web applications and would also be backwards-compatible with the old HTML.</p><p>In 2007, the W3C agreed with WHATWG&#8217;s point of view. The two groups remained separate but worked together on creating a new version of HTML, naming it &#8220;HTML5.&#8221;</p><p>The two groups are still working together as the HTML5 specification isn&#8217;t finalized as of this article, but it&#8217;s still possible to use it to create websites and web applications&#8230;as many do.</p><h3><a id="Semantic-Markup">Semantic Markup</a></h3><p>Semantic markup is HTML written in a way that gives site content specific meaning.  Semantic markup is <em>not</em> a new a concept: it existed well before HTML5.</p><p>HTML5 does create excellent semantic markup though&#8230;better than earlier HTML versions. Metaphorically speaking, the semantic markup of earlier versions tells the world, &#8220;this is some site content&#8221; while HTML5 semantic markup tells the world, &#8220;this is some site content, now let me give you some detailed information about it.&#8221;</p><p>Sites written with semantic markup are easier to read on a multitude of devices: desktops, laptops, smartphones, screen-readers for the disabled, gaming consoles, just to name a few.  But search engines also like semantic markup&#8230;so much so that web designer <a href="http://twitter.com/#!/zeldman/statuses/1137456194">Jeffrey Zeldman said it best in 2009:</a><div style="margin:0px auto; text-align:center; width: 650px; font-style:italic; padding:5px 0 25px 0;"><em>&#8220;Client who saves $5,000 buying cut-rate non-semantic HTML will later spend $25,000 on SEO consultant to compensate&#8221;</em></div><p>Correct! Site content wrapped in non-semantic markup is tough for search engines to understand; therefore, it&#8217;s tough for search engines to rank and list in their search results.</p><p>Hiring an SEO company to fix this is costly. If your site is coded with semantic markup at the beginning, this cost can be, at the very least, reduced.</p><p>To be clear: semantic markup up will <em>not</em> improve a site&#8217;s search engine ranking. It just makes it easier for search engines to <em>understand</em> a site&#8217;s content, which in turn, makes it easier to rank in search resullts.</p><p>Think of site content as a pirate&#8217;s treasure chest full of gold. Semantic markup gives search engines an awesome treasure map.</p><p>One last note on the subject: sites written with semantic markup are said to be &#8220;following web standards.&#8221; Web developers have been coding with web standards for years, but too many haven&#8217;t. A push for <em>all</em> developers to use web standards has always existed, but HTML5 has strengthened this push more than ever before.</p><h3><a id="Web-Applications">Web Applications</a></h3><p>A <em>website</em> is a site that gives people information, but doesn&#8217;t offer a lot in terms of interaction. People may be able to fill out a form of some sort while visiting the site, but the interaction won&#8217;t go much beyond that.</p><p>A <em>web application</em> is a site that gives people information and offers a lot in terms of interaction.  Some interaction examples are:</p><ul><li>adding copy, images &amp; videos.</li><li>removing copy, images &amp; videos.</li><li>editing copy, images &amp; (sometimes) videos.</li><li>writing product reviews.</li><li>sending messages to people.</li><li>letting people know your current location.</li></ul><p>Looking at this list, Facebook, Twitter, FourSquare, and Yelp are great examples of web applications.</p><p>Other web application examples include: Hotmail, Yahoo Mail, Gmail, Google Docs and Google Maps.</p><p>HTML5&#8242;s role in web application development is a bit tricky to describe: start with understanding that there&#8217;s &#8220;HTML5&#8243; and there&#8217;s &#8220;HTML5-related technology.&#8221;</p><p>The following is an incomplete list of things that are part of HTML5:</p><ul><li><strong>Video:</strong> playing video on a website without needing things like Flash.</li><li><strong>Audio:</strong> playing audio on a website without the need for plugins.</li><li><strong>Canvas:</strong> using code to automatically draw stuff on a website.</li><li><strong>Drag &amp; Drop:</strong> dragging and dropping stuff on a website.</li><li><strong>Application Cache:</strong> storing website content, such as images, on a device, making the site run faster.</li></ul><p>The following is an incomplete list of things that are HTML5-related technologies:</p><ul><li><strong>WebGL:</strong> creates 3D graphics on a website.</li><li><strong>Web Workers:</strong> a method of running and storing website code behind the scenes.</li><li><strong>Geolocation:</strong> lets websites know where site visitors are geographically located.</li></ul><p>HTML5 and HTML5-related technologies can be combined with other technologies to create compelling web applications.</p><p>For the sake of easy explanations, I called these things &#8220;HTML5-related technologies&#8221; but I can&#8217;t stress enough that they&#8217;re <em>not</em> HTML5. They&#8217;re &#8220;HTML5-related&#8221; at best and even that&#8217;s a stretch of the terminology.</p><p>Many don&#8217;t care about this the proper term usage but do not be surprised if a real stickler comments on this article, telling me that calling these things &#8220;HTML5-related&#8221; is a no-no.  If you want the techie details on this, visit <a href="https://developer.mozilla.org/en/HTML/HTML5">MDN&#8217;s HTML5 page</a> and take note of the section called &#8220;<a href="https://developer.mozilla.org/en/HTML/HTML5#Technologies_often_called_part_of_HTML5_that_aren't">Technologies often called part of HTML5 that aren&#8217;t</a>.&#8221;</p><h3><a id="Mobile-Web-Development">Mobile Web Development</a></h3><p>The web browsers pre-installed in the majority of mobile devices released in the past two years support HTML5: both websites and web applications.</p><p>First, understand that there are native applications and there are mobile web applications. Native applications are what are commonly called &#8220;apps&#8221; or &#8220;native apps;&#8221; small applications that you download from places such as Apple&#8217;s App Store or Google&#8217;s Android Market.  Mobile web applications are applications that run inside a mobile web browser such as Safari Mobile or Opera Mini; they&#8217;re called &#8220;mobile web apps&#8221; nowadays.</p><p>So if you&#8217;re on an iPhone, you can open the Safari Mobile web browser (a native app) and go to <a href="http://m.facebook.com/">Facebook&#8217;s mobile site</a> (a mobile web app).  Or, you can open the App Store (another native app) and download the Facebook application (yet, another native app) and use Facebook from there.</p><p>The good thing about native apps is they have more functionality than mobile web apps. The good thing about mobile web apps is that they&#8217;re less expensive to create than native apps.</p><p>A native app that lives on your smartphone can use other native apps to aid in a particular task&#8230;the camera, the address book, directional apps like the compass and the maps, etc. Except for <em>very</em> few instances, mobile web apps can&#8217;t do any of this as of this article; therefore, native apps have more functionality.</p><p>But it&#8217;s always a good idea to make your app to work on as many devices as possible, and doing so can be expensive.  The current cost for creating an app that works on <em>just</em> iPhones and Androids is in the five-figure range.  Mobile web apps are coded to work on mobile web browsers, which practically every mobile device has. So a mobile web app will work on almost any mobile device, and will be cheap to create when compared to the cost for creating a native app for <em>every</em> device.</p><p>HTML5 is well-suited for mobile web apps for a lot a reasons, a big one being the above-mentioned application cache.</p><p>When combined with certain HTML5-related technologies, application cache allows mobile web apps to work on devices <em>even if the device doesn&#8217;t have an internet connection!</em> These apps would probably need a connection to work as fully intended, but they can still do lots of things offline.</p><p>Best of all mobile web browsers support many HTML5 features already. Non-mobile browsers are catching up, but the mobile browsers adopted them first and are ahead in the race as a result.</p><p>Because of their offline functionality and early adoption rate among mobile devices, lots of web developers are promoting HTML5 mobile web apps as a viable alternative to native apps.  Mobile web apps will need to be able access things like the camera if they expect to beat the native guys, but I believe they&#8217;ll have access to many of these things eventually.</p><h3><a id="Making-The-Site-Look-Pretty">Making The Site Look Pretty</a></h3><p>There are some HTML5 things that can make sites look good, but very little. And again, these things don&#8217;t work in many desktop browsers, which are still used more than mobile browsers.</p><p>So to make a site look good in as many browsers as possible, these three things are currently the best tools to do so:</p><ul><li style="list-style-type: decimal;"><strong>CSS3:</strong> applies pictures, colors and few cool effects to websites.</li><li style="list-style-type: decimal;"><strong>JavaScript:</strong> creates interactivity on a website.</li><li style="list-style-type: decimal;"><strong>JavaScript-related technologies:</strong> <a href="http://jquery.com/">jQuery</a> is the biggest one of these right now.</li></ul><p>These things are not HTML5, but you will see them used in both HTML5 websites and web applications.</p><h3><a id="How-Is-HTML5-Being-Used-As-of-This-Article">How Is HTML5 Being Used As of This Article?</a></h3><p>In many ways&#8230;</p><ul><li>HTML5 games make up a bulk of the HTML5 web apps being created: <a href="http://techcrunch.com/2011/01/27/facebook-bret-taylor/">Facebook is very committed to HTML5 games</a>.</li><li>Web designers are excelling at creating sites with semantically correct HTML5 markup and making them look pretty. <a href="http://bostonglobe.com/">The Boston Globe</a> is one of the most celebrated of these sites but <a href="http://html5gallery.com/">HTML5 Gallery</a> also provides some nice samples.</li><li>Web applications are popping up everywhere.  One of my favorites is <a href="https://web.tweetdeck.com/">TweetDeck Web</a>.</li><li>There are  a few mobile web apps out there.  Some use a lot of HTML5 and its related technologies, some use just a little of it. <a href="http://www.jqmgallery.com/">jQuery Mobile Gallery</a> is site that uses a fair amount of HTML5 stuff; the sites they display use HTML5 to varying degrees.</li></ul><h3><a id="How-Can-Businesses-Use-HTML5-TML5-Related-Technologies-Right-Now">How Can Businesses Use HTML5 &#038; HTML5 Related-Technologies Right Now?</a></h3><p>I can&#8217;t stress the importance of web standard semantic markup enough. Businesses that don&#8217;t have it in their sites need to get it in there sooner, not later. They should either edit their current site and add the markup, or plan a site redesign that will include such markup.</p><p>If businesses go with the redesign, they can also make it look pretty at that point using CSS, JavaScript and JavaScript-related technologies.</p><p>As for web applications and mobile web development, I have to refer to a previous statement&#8230;creating websites and web applications with HTML5 is a best practice but, in all honesty, not a requirement.</p><p>For example: Facebook and Twitter&#8217;s desktop browser applications converted to HTML5 only recently, but millions of people were using them as web apps before that. And both have robust mobile web applications, each one created with an older version of HTML.   This is also true for CNN, Fox News, Sephora, ESPN, Ford, Dollar General&#8230;I can probably go on and on.</p><p>So there&#8217;s no clear path here: using HTML5 certainly helps but it seems that <em>not</em> using it doesn&#8217;t hurt. Regardless of this, I believe that all sites and web apps from here on in, should be created with HTML5.</p><p>I also believe that deciding whether to use HTML5 should not be the first task of a business-that should be focusing on delivering high quality content.</p><p>I&#8217;m basing this opinion on what I learned at <a href="http://kaidez.com/nyc-social-media-week-event-recap-cross-mobile-promotion/">the mobile promotion panel during Social Media Week 2011</a>. Over and over again, the panelists stress how the mobile web was a better promoter than the native app and that we should spend more time developing an effective content strategy instead of following tech trends. Not one panelist mentioned HTML5 and there were many developers working with it at that time.</p><p>So my HTML5 suggestions for business don&#8217;t have that much to do with HTML5.  They are:</p><ul><li style="padding-bottom:13px;"><strong>Confirm that your web developer or agency will create your site with HTML5 semantic web standard markup:</strong> Most do, but double-check anyway.</li><li style="padding-bottom:13px;"><strong>Remember that HTML5 isn&#8217;t the only thing that makes your site look good:</strong> The CSS3 and JavaScript stuff is very important here.</li><li style="padding-bottom:13px;"><strong>Develop your content strategy first:</strong> doing so will help you decide what parts of your content are the most important.</li><li style="padding-bottom:13px;"><strong>Don&#8217;t think you need to create an HTML5 app:</strong> You may find that you don&#8217;t need it after you devise your content strategy and that a website will do the job just fine.</li></ul><p>In closing, HTML5 is a highly discussed and debated subject right now and some may agree or disagree with what&#8217;s being said here.  So please feel free to comment on this article and post your opinions.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/simple-html5-explanation/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SCREENCAST TUTORIAL: JavaScript for() loop That Creates A jQuery Fade In/Fade Out</title><link>http://kaidez.com/javascript-for-loop-creates-jquery-fade/</link> <comments>http://kaidez.com/javascript-for-loop-creates-jquery-fade/#comments</comments> <pubDate>Mon, 05 Mar 2012 09:50:07 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Tutorials]]></category><guid isPermaLink="false">http://kaidez.com/?p=5246</guid> <description><![CDATA[VIEW THE DEMO FIRST &#187; My most visited article (as of this one) is my jQuery fade in/fade out tutorial. Thanks to a clean &#60;title> tag and a click-inducing meta description, this 58-post blog (also, as of this one) gets &#8230; <a href="http://kaidez.com/javascript-for-loop-creates-jquery-fade/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p><a href="http://jsfiddle.net/kaidez/6xfKN/33/" target="_blank">VIEW THE DEMO FIRST &raquo;</a></p><p>My most visited article (as of this one) is my <a href="http://kaidez.com/tutorial-simple-jquery-fade-in-fade-out/">jQuery fade in/fade out tutorial</a>.  Thanks to a clean <code>&lt;title></code> tag and a click-inducing meta description, this 58-post blog (also, as of this one) gets roughly 300 unique visits a day&#8230;all of which, I&#8217;m humbled by.</p><p>As I saw how people were using the tutorial&#8217;s code, a need to make it dynamic became very obvious. I did so with a JavaScript for() loop&#8230;.here&#8217;s the complete code breakdown:</p><h2>HTML</h2><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;en&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main.css&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>jQuery fade-ins with a JavaScript for() loop<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>	
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elem0&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toBeFaded&quot;</span>&gt;</span>Here's the first message...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elem1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toBeFaded&quot;</span>&gt;</span>We have second one here...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elem2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toBeFaded&quot;</span>&gt;</span>And here's the third message...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;elem3&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toBeFaded&quot;</span>&gt;</span>OMG!!! Here's the fourth message!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
 	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
  	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fadeCode.js&quot;</span> <span style="color: #000066;">defer</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;defer&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div><h2>CSS (main.css)</h2><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.toBeFaded</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">70pt</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><h2>JavaScript (fadeCode.js)</h2><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #003366; font-weight: bold;">var</span> yourFade <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// the amount of time in seconds that the elements will fade in AND fade out</span>
     yourDelay <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// the amount of time in seconds that there will be a delay between the fade ins and fade outs</span>
     fadeTime <span style="color: #339933;">=</span> yourFade <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//convert fade seconds to milliseconds (1000)</span>
     delayTime <span style="color: #339933;">=</span> yourDelay <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// convert delay seconds to milliseconds (2000)</span>
     totalTime <span style="color: #339933;">=</span> fadeTime <span style="color: #339933;">+</span> delayTime<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//3000 milliseconds...needed for all those delays we talked about</span>
     allElems<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// find out exactly how many page elements have the 'toBeFaded' class (4)</span>
     elemNoFade<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// Will help us find the last element represent the last element (3)</span>
     i<span style="color: #339933;">,</span>
     fadingElem<span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> allElems <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.toBeFaded'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> elemNoFade <span style="color: #339933;">=</span> allElems <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> allElems<span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	fadingElem <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#elem&quot;</span> <span style="color: #339933;">+</span> i<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
		$<span style="color: #009900;">&#40;</span>fadingElem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span>fadeTime<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span>fadeTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">===</span> elemNoFade<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>fadingElem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span>totalTime <span style="color: #339933;">*</span> i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span>fadeTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>fadingElem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span>totalTime <span style="color: #339933;">*</span> i<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span>fadeTime<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span>fadeTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>What&#8217;s happening here:</p><ul><li style="padding-bottom:13px;">The elements that you want to fade in and out <em>must</em> be placed on your page with a unique ID that starts with &#8220;elem&#8221; and ends with a number. The numbers <em>must</em> start counting at 0 (ie. <code>'elem0'</code> first, <code>'elem1'</code> next, <code>'elem2'</code> after that, etc&#8230;)</li><li style="padding-bottom:13px;">Each fading page element <em>must</em> have a classname of <code>'toBeFaded'</code>.</li><li style="padding-bottom:13px;">The JavaScript uses those IDs and classnames to detect the page elements and, based on this detection, create jQuery code that fades the elements in and out.</li><li style="padding-bottom:13px;">There will be a delay between each element&#8217;s fade in and fade out. The JavaScript dynamically detects the length of the delay.</li><li style="padding-bottom:13px;">If you want to adjust the seconds of fade in and fade out time, change the number value of the <code>'yourFade'</code> variable in the JavaScript.</li><li style="padding-bottom:13px;">If you want to adjust the seconds of the delay, change the number value of the <code>'yourDelay'</code> variable in the JavaScript.</li></ul><p>The code is fully dynamic: all you have to do is layout the HTML and tweak the JavaScript variables as described above; the code does the rest.  You can style things however you want as the CSS but you probably want to keep the <code>display:none</code> and <code>position:absolute</code> settings.</p><p>As far as teaching people <em>how</em> to do this, I always assume that those reading my code are web design/dev beginners and try to walk them through it. But the JavaScript for() loop is what&#8217;s running things here&#8230;walking through that isn&#8217;t a simple process.</p><p>I remember struggling with the JavaScript for() loop and believe that others do so as well.  So I&#8217;ve created this three-part screencast tutorial that explains the JavaScript for() loop in excruciating detail.</p><p>No doubt about it, this screencast tutorial is for the JavaScript beginner.  The JavaScript pro may be bored by it; however, if you are a JavaScript pro but have never read either Douglas Crockford&#8217;s <a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">JavaScript: The Good Parts</a> or Stoyan Stevanov&#8217;s <a href="http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752/ref=sr_1_1?s=books&#038;ie=UTF8&#038;qid=1330662444&#038;sr=1-1">JavaScript Patterns</a>, you may want to check out the third video.</p><p>Enjoy!!!</p><h2>Part One</h2><p><iframe width="560" height="315" src="http://www.youtube.com/embed/Wc_kLZTyTjQ" frameborder="0" allowfullscreen></iframe></p><h2>Part Two</h2><p><iframe width="560" height="315" src="http://www.youtube.com/embed/q0EYJfOz9Mg" frameborder="0" allowfullscreen></iframe></p><h2>Part Three</h2><p><iframe width="560" height="315" src="http://www.youtube.com/embed/tFRC1tKeMJ0" frameborder="0" allowfullscreen></iframe></p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/javascript-for-loop-creates-jquery-fade/feed/</wfw:commentRss> <slash:comments>27</slash:comments> </item> <item><title>REVIEW: HTML5 Games Development by Example: Beginner’s Guide</title><link>http://kaidez.com/html5-games-development-book/</link> <comments>http://kaidez.com/html5-games-development-book/#comments</comments> <pubDate>Fri, 07 Oct 2011 13:26:54 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Reviews]]></category><guid isPermaLink="false">http://kaidez.com/?p=5200</guid> <description><![CDATA[No doubt about it: the demand for HTML5 games is high and will only get higher. Game development has always been a lucrative skillset to possess and thanks to HTML5, web-based game development is a bit easier. So if you &#8230; <a href="http://kaidez.com/html5-games-development-book/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>No doubt about it: the demand for HTML5 games is high and will only get higher. Game development has always been a lucrative skillset to possess and thanks to HTML5, web-based game development is a bit easier.</p><p>So if you already have basic HTML5, CSS and JavaScript skills, Packt Publishing&#8217;s <strong><em><a href="http://www.packtpub.com/html5-games-development-using-css-javascript-beginners-guide/book ">HTML5 Games Development by Example: Beginner’s Guide</a></em></strong> is a learning resource that&#8217;s worth checking out if you want to get into game developmet. And if you don&#8217;t want to get into gaming, it may be worth a purchase anyway.</p><p><a href="http://kaidez.com/wp-content/uploads/2011/10/html5GamesPackt.jpg" rel="lightbox[5200]"><img src="http://kaidez.com/wp-content/uploads/2011/10/html5GamesPackt.jpg" alt="HTML5 Games Development by Example: Beginner’s Guide book and eBook" title="html5GamesPackt" width="150" height="200" class="alignright size-full wp-image-5193" /></a>The book offers six step-by-step HTML5 game creation tutorials, starting with a simple ping-pong game and gradually getting more difficult, using things like WebSockets. It uses a varied array of coding techniques to create HTML5 games: jQuery, HTML5 audio, CSS3, JSON and (wow!) <a href="http://nodejs.org/">node.js</a>.  I went through the coding examples and didn&#8217;t see any errors.  There certainly some stylistic differences in how page elements were rendered across browsers and devices, but nothing so glaring to the point that I would badmouth the code.</p><p><em>HTML5 Games</em> also holds your hand quite nicely through the process.  At times, it goes through a set of steps, then asks the reader &#8220;What just happened?&#8221;, clarifying the coding steps you just performed.  It also, at times, makes sure that your brain retained the lessons you learned as pop quizes show up in the content.</p><p>The book is certainly good for learning HTML5 gaming development but I have to say, it&#8217;s also if you have no plans to get into this realm.  While this book demonstrates many coding techniques, four in particular jumped out at me:</p><ul><li style="padding-bottom:13px;"><strong>Canvas</strong> &#8211; this is one of the most talked about HTML5 APIs&#8230;<em>HTML5 Games</em> covers it well and in-depth.</li><li style="padding-bottom:13px;"><strong>Cache manifest &#038; local storage</strong> &#8211; sorely underrated as of this article, both of these things allow for the creation of browser-based games and web applications that can run without an internet connection. <em>HTML5 Games</em> reviews them very early on.</li><li style="padding-bottom:13px;"><strong>The importance of JavaScript in HTML5 application development</strong> &#8211; My opinion is that this point hasn&#8217;t been drilled enough into the heads of web designers with limited web development skills. If that&#8217;s you, read this book and you&#8217;ll be better-prepared.</li></li><li><strong>JavaScript best practices</strong> &#8211; things like &#8220;limit your global JavaScript variables!&#8221; are mentioned. This is good.</li></ul><p>Factor these four topics in with the ones mentioned earlier (node.js, JSON, etc.) and <em>HTML5 Games</em> is a pretty good primer of the most-desired web dev skillsets employees are looking for as of this article.  Page 2 of the book states that it&#8217;s for game designers, but I think that any intermediate web developer can better their coding habits if they go through the six exercises. You become a better developer by working on many different projects&#8230;working on gaming projects like the ones discussed in the book is no exception.</p><p>But it also states on page 2 that you should have a &#8220;basic understanding of HTML, CSS and JavaScript,&#8221; which is spot-on correct. There are no extensive discussions on the semantic meaning of HTML5 tags or the hows-and-whys of jQuery, and those with a firm handle on JavaScript custom objects will breeze through this book.  So the web development <em>beginner</em> will struggle a bit with <em>HTML5 Games</em> if they don&#8217;t understand those core concepts.</p><p>I walked away learning more than I did before after finishing <strong><em>HTML5 Games Development by Example: Beginner’s Guide</em></strong>.  That&#8217;s a strong sign of quality learning resource so I suggest it.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/html5-games-development-book/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Remembering Steve Jobs</title><link>http://kaidez.com/remembering-steve-jobs/</link> <comments>http://kaidez.com/remembering-steve-jobs/#comments</comments> <pubDate>Thu, 06 Oct 2011 05:00:41 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Personal]]></category><guid isPermaLink="false">http://kaidez.com/?p=5141</guid> <description><![CDATA[I&#8217;m sitting here, typing away on my Mac Intel, syncing podcasts to my iPhone, my Powermac G4 self-customed web server humming two feet away, wondering what&#8217;s the best way to recall a visionary in writing. It&#8217;s tough&#8230;a loss like this &#8230; <a href="http://kaidez.com/remembering-steve-jobs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>I&#8217;m sitting here, typing away on my Mac Intel, syncing podcasts to my iPhone, my Powermac G4 self-customed web server humming two feet away, wondering what&#8217;s the best way to recall a visionary in writing.  It&#8217;s tough&#8230;a loss like this doesn&#8217;t happen everyday.</p><p>But it happened and needs to documented by as many as possible.  On October 5, 2011, Steven Paul Jobs, Apple co-founder, lost his seven year battle with cancer.  He changed how we walk down the street so he must be remembered.</p><p>In this generation, no one will deliver the legacy of innovation, creativity and design that Steve Jobs left us.  He loved (<em>loved</em>) going to work every day: not because Apple was making billions of dollars (although I&#8217;m sure it helped), but because he couldn&#8217;t wait to see what the company would think of next.</p><p><a href="http://kaidez.com/wp-content/uploads/2011/10/sjPic.jpg" rel="lightbox[5141]"><img src="http://kaidez.com/wp-content/uploads/2011/10/sjPic.jpg" alt="" title="sjPic" width="250" height="250" class="alignleft size-full wp-image-5149" /></a>Being a web developer and making a blanket statement, I see two standout contributions from Jobs.  And I have to go all &#8220;computer geek&#8221; when I talk about the first one: the OS X operating system.</p><p>Released in 2001, OS X was UNIX-like operating system based on one of Jobs&#8217; previous creations, Darwin OS.  The open source web development community adopted at it lightning speed-the fact that a group dedicated to creating and freely giving away high-quality software were spending four figure amounts on Macs was something I always found humorously ironic.</p><p>But they did and as a result, the Mac is out-of-the-box ready for open source web and software development. Steve made sure that an entire generation of programmers had all the tools they needed to potentially change the world.  The general public will never fully realize the impact of what Jobs was doing here.</p><p>The general public was, however, front-and-center for Jobs&#8217; second key contribution, which was how easy he made home computing.  One of the most common things I hear when people compare Macs to Windows-based machines, &#8220;You plug in a Mac and it just works.&#8221; No setup discs, no multiple virus updates.  Macs are simple machines than an average consumer can figure out in little time.</p><p>This idea of &#8220;simplicity within technology&#8221; is best exemplified in the iPhone.  For a few years prior to the iPhone&#8217;s release, every major mobile player at the time, Nokia, Motorola et al. were all promising to deliver on convergence, the idea that one handheld device would handle all your digital needs.  Under Steve Jobs&#8217; watch, Apple delivered it first&#8230;.and best.</p><p>An ex-coworker of mine blogged how she sleeps with her iPhone, letting her boyfriend know that it comes first in the relationship.  We are glued to our iPhones for news, music and information, all the while not paying attention to whether or not the cross signal is green.  Yes, Steve Jobs changed how we walk down the street.</p><p>As geeky and granular as all these seems so far, stop and think for a second.  How many times in your lifetime will you encounter one mind that delivers so much creative thought in so short a time span? And what inspiration will take from it?  And <em>if</em> you take from it, what will you actually <em>do</em> with it once you have it?</p><p>Dave Ramsey is financial guru/author/radio host that&#8217;s quite conservative, socio-politically.  So socio-politically, I disagree with most of what he says but he&#8217;s the only money guru that drives the point home that &#8220;All debt is bad and is to be avoided at all costs.&#8221; That worldview has saved me in more ways than I can count because I choose to filter out Ramsey&#8217;s political statements and pull the parts that help me the best.</p><p>The good parts of Steve Jobs&#8217; legacy are plentiful and can be easily picked out&#8230;oh, so very easily.  And those that do so, those that realize that thinking outside of the box sparks revolution, those that see how simplifying the difficult makes life better, they will be the next leaders. They <em>will</em> create the next life-changing company. They <em>will</em> be the catalyst for the next Arab Spring. They <em>will</em> be the next ones that are extraordinary.</p><p>Those that focus on the negative aspects of his life, his lack of philanthropy, his need to control everything, his past estrangement with his daughter, will never take inspiration from the positive and are destined for life in the middle.  Not a life on the sidelines but one in the middle.  A life that will invoke for the greater good at best, but never create for it.  They will never realize their full potential.</p><p>Don&#8217;t you dare shed a tear for Steve Jobs.  He left this mortal coil knowing that in parallel, he created and inspired a generation to do better. The night he died, I saw a Facebook post saying that Jobs and DaVinci are probably up in heaven inventing some fascinating things.  Thanks to Steve, that level of inventiveness already exists on Earth.</p><p>So the next time I&#8217;m walking to my morning commute bus, cueing up Stereolab on my iPhone while reviewing emails and world events as I unknowingly step in dogsh*t, I&#8217;ll know that Steve changed how I walk down the street, and I&#8217;ll know how much happier I am because of it.</p><p>RIP Steve Jobs.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/remembering-steve-jobs/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>5 Mobile Web Development Best Practice Resources</title><link>http://kaidez.com/mobile-web-development-best-practice-resources/</link> <comments>http://kaidez.com/mobile-web-development-best-practice-resources/#comments</comments> <pubDate>Thu, 16 Jun 2011 09:57:40 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Coding Best Practices]]></category><guid isPermaLink="false">http://kaidez.com/?p=4876</guid> <description><![CDATA[My last batch of articles have discussed which mobile web development best practices I&#8217;ve adopted. I obviously can&#8217;t claim them as my own creation and should share my resources for these practices. Some are more mobile-specific then others but all &#8230; <a href="http://kaidez.com/mobile-web-development-best-practice-resources/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>My last batch of articles have discussed which mobile web development best practices I&#8217;ve adopted. I obviously can&#8217;t claim them as my own creation and should share my resources for these practices.</p><p>Some are more mobile-specific then others but all focus on optimizing sites for speed: the number one mobile web development best practice:</p><h2>1) Steve Souders</h2><p>The one that really showed developers the way in terms of creating fast-loading sites.  Formerly at Yahoo! and now at Google, <a href="http://stevesouders.com/">Steve Souders</a> is <em>the</em> speed site guru mostly on the strength of his two books: <a href="http://www.amazon.com/gp/product/0596529309?ie=UTF8&#038;tag=stevsoud-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596529309"><em>High Performance Web Sites</em></a> and <a href="http://www.amazon.com/gp/product/0596522304?ie=UTF8&#038;tag=stevsoud-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596522304"><em>Even Faster Websites</em></a>.  Paul Irish took the best tips from both of these books and applied them to the <a href="http://html5boilerplate.com/docs/#Build-script">HTML5 Boilerplate build script</a>.</p><h2>2) PPK</h2><p>Web developer Peter-Paul Koch, also known as PPK, is next on the speed guru list. He&#8217;s well-known for performing tons of mobile device/browser tests, displaying the results on <a href="http://www.quirksmode.org/mobile/">the mobile section of his Quirksmode blog</a>&#8230;spend some reading the Compatibility table on this page.</p><p>As he lives in Amsterdam, PPK can perform thorough tests on the <a href="http://symbian.nokia.com/">Symbian</a> browser, which not only gets heavy usage in Europe, but is also the world&#8217;s most popular mobile web browser. So&#8230;American-based web developers need to read his Symbiam results on his <a href="http://www.quirksmode.org/">Quirksmode blog</a> because they will have to code for it sooner than later.</p><h2>3) Yahoo&#8217;s YUI and YDN blogs</h2><p>Right now, Yahoo! is to site optimization what Google is to SEO: a well-respected authority in their area of expertise.  Nowhere is this more clear than within <a href="http://www.yuiblog.com/blog/category/performance/">the Performance category of their Yahoo! User Interface Blog (or just the YUIBlog)</a>.  All of these posts offer great site speed tips, particularly the ones by <a href="http://www.phpied.com/">Stoyan Stefanov</a>.</p><p>Yahoo! also maintains the Yahoo! Developer Network blog (YDN), which doesn&#8217;t have the depth of site speed advice that YUI does, but is still good.  Their &#8220;<a href="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a>&#8221; article is pretty much required reading for any web developer right now, plus, YDN maintains the awesome Steve Souders-created <a href="http://developer.yahoo.com/yslow/">YSlow browser plugin</a>, used for testing a web page&#8217;s optimization.</p><p><em>(A related side-note: Yahoo released a <a href="http://developer.yahoo.com/blogs/ydn/posts/2011/06/yslowmobile/">beta version of YSlow for Mobile</a> the day before this article&#8217;s posting.  I downloaded it and believe me when I say that you should too). </em></p><h2>4) YayQuery podcast with John Resig</h2><p><a href="http://yayquery.com/">YayQuery</a> is an excellent jQuery podcast hosted by four jQuery experts: Paul Irish, Rebecca Murphey, Adam J. Sontag and Alex Sexton.  jQuery creator John Resig appeared on the show in mid-2010, mostly discussing <a href="http://jquerymobile.com/">jQuery Mobile</a>.</p><p>Prior to jQ Mobile&#8217;s release, Resig did a boatload of mobile device research, all of it interesting, quite a bit of it surprising.  He shared his findings during this podcast&#8230;it&#8217;s a must-watch.</p><p><iframe src="http://player.vimeo.com/video/12166734?title=0&amp;byline=0&amp;portrait=0" width="400" height="225" frameborder="0"></iframe></p><h2>5) HTML5 Boilerplate Build Script</h2><p><a href="http://kaidez.com/html5-boilerplate-version-1/">I&#8217;ve  mentioned this before</a> but let me be crystal clear right now: HTML5 Boilerplate&#8217;s build script does an incredible job of optimizing site files.  With a simple command line prompt (or Windows batch file), you can run all your site files through YUI Compresser, optipng, jpegtran and many other applications to dramatically reduce their file size.  The end-result is a faster-loading site.</p><p>Watch the Boilerplate  how-to video..it&#8217;s well worth 28 minutes of your time:</p><p><iframe width="425" height="349" src="http://www.youtube.com/embed/OXpCB3U_4Ig" frameborder="0" allowfullscreen></iframe></p><p>Those are my biggies&#8230;feel free to share what you think are good mobile web development best practices because I can&#8217;t name them all!</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/mobile-web-development-best-practice-resources/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>2 Bad Things About the Facebook App Setup</title><link>http://kaidez.com/2-bad-facebook-app-things/</link> <comments>http://kaidez.com/2-bad-facebook-app-things/#comments</comments> <pubDate>Fri, 10 Jun 2011 09:57:49 +0000</pubDate> <dc:creator>kaidez</dc:creator> <category><![CDATA[Coding Best Practices]]></category><guid isPermaLink="false">http://kaidez.com/?p=4848</guid> <description><![CDATA[For the Almay/Facebook project I recently worked on, I had to create a Facebook app under their new set of rules, which was interesting. Creating Facebook apps, which are basically web pages, used to require the Facebook Markup Language (FBML) &#8230; <a href="http://kaidez.com/2-bad-facebook-app-things/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>For the <a href="http://kaidez.com/almay-facebook-page/">Almay/Facebook</a> project I recently worked on, I had to create a Facebook app under their new set of rules, which was interesting.</p><p>Creating Facebook apps, which are basically web pages, used to require the Facebook Markup Language (FBML) which is simply a flavor of XML.  Facebook recently changed this, saying that developers now simply need to create FB app web pages with HTML, CSS, JavaScript, etc., then host the pages on their own web server.  These pages then get fed to Facebook via an iframe.</p><p>This is an easier web development process and all the page content displays fine.  But I&#8217;m in a headspace of creating page code that&#8217;s as optimized and as fast-loading as I can get it&#8230;.my current <a href="http://kaidez.com/mobile-web-development-best-practices-starting-tips/">&#8220;thinking mobile&#8221;</a> process.  That being said, there are two things about the Facebook app setup which, I think, could be made better from a page optimization standpoint.</p><p>And it all points back to a JavaScript file named &#8220;all.js&#8221; that needs to be installed on your web pages in order for the app to work:</p><h2>1. CSS Expressions</h2><p>According to my app page&#8217;s <a href="http://developer.yahoo.com/yslow/">YSlow</a> report, this &#8220;all.js&#8221; file is capable of inserting three inline CSS expressions on to the page.  Affecting Internet Explorer 8 and lower only, CSS expressions are CSS selectors that are updated and manipulated with JavaScript.  Here&#8217;s the CSS expression example from <a href="http://developer.yahoo.com/performance/rules.html#css_expressions">YDN page</a>:<br /> <br /> <span class="codeFont" style="font-size: 14px;"> background-color: expression( (new Date()).getHours()%2 ? &#8220;#B8D4FF&#8221; : &#8220;#F08A00&#8243; );</span><br /> <br /> Basically, this code updates the background color ever hour; however, it runs much more frequently then that.  Simple things like scrolling and mouse movements can fire this code off, which slows down the page overall.</p><p>This sucks, but no where NEAR as bad as&#8230;</p><h2>2. Render Tree Reflows</h2><p>According to Safari&#8217;s Activity Monitor, the &#8220;all.js&#8221; dynamically adjusts lots of DOM properties when scrolling the page.  One simple scroll changed the following DOM properties on the fly:</p><ul><li class="codeFont">clientWidth</li><li class="codeFont">clientHeight</li><li class="codeFont">scrollLeft</li><li class="codeFont">scrollTop</li><li class="codeFont">offsetLeft</li><li class="codeFont">offsetTop</li></ul><p>Changing properties like this triggers a render tree reflow, the recalculation of a web page&#8217;s layout and geometry.  All of this takes time and browser resources, meaning all of this slows down a page&#8230;no good.</p><p>Paul Irish discusses this in his most-recent how-to video, &#8220;HTML5, CSS3, and DOM Performance&#8221; that&#8217;s listed below.  He alludes to Stoyan Stefanov&#8217;s brilliant <a href="http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/">reflow/relayout article</a>, which is the end-all-be-all discussion on the subject.</p><p><iframe width="425" height="349" src="http://www.youtube.com/embed/q_O9_C2ZjoA" frameborder="0" allowfullscreen></iframe></p><p>So Facebook apps are now easier to create but, I feel, still need improvement in terms of page optimization.  Feel free to comment and agree or disagree.</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://kaidez.com/2-bad-facebook-app-things/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss><!-- Served from: kaidez.com @ 2012-05-25 12:52:57 by W3 Total Cache -->

