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

<channel>
	<title>Delivering Quality &#187; JavaScript</title>
	<atom:link href="http://www.markdeepwell.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markdeepwell.com</link>
	<description>A Software Developers View of the World</description>
	<lastBuildDate>Sat, 31 Dec 2011 22:41:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Web Development Best Practices</title>
		<link>http://www.markdeepwell.com/2011/01/web-development-best-practices/</link>
		<comments>http://www.markdeepwell.com/2011/01/web-development-best-practices/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 05:01:47 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Future Proof]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=584</guid>
		<description><![CDATA[Choosing a Technology Framework Does it really matter if you use ASP.NET MVC, Struts 2, Yii, or Rails? Well it might, but for many websites these modern frameworks are just as competitive as the next. Use the stack that is most appropriate for your customer&#8217;s situation and is the best choice at the time. Since [...]]]></description>
			<content:encoded><![CDATA[<h3>Choosing a Technology Framework</h3>
<p>Does it really matter if you use ASP.NET MVC, Struts 2, Yii, or  Rails? Well it might, but for many websites these modern frameworks are  just as competitive as the next. Use the stack that is most appropriate  for your customer&#8217;s situation and is the best choice at the time. Since  this is the real world, it will probably change a couple of years in the  future.</p>
<h3>Leverage Community Extensions</h3>
<p>Each framework out there has libraries of modules, extensions or plugins that enhance functionality and provide features that would you otherwise would need to write yourself. If it exists, and it&#8217;s in good shape, don&#8217;t write it yourself, leverage existing extensions that are appropriately licensed for your project.</p>
<h3>Future Proof your URLs</h3>
<p>It no longer makes sense to have a web site with extensions, be it .html, .php, .jsp, or .whatever you can think of. <a href="http://arstechnica.com/">Arstechnica</a> even created their own .ars, for no reason that I could tell. Yes the web started with .html because websites were simply serving static files, but that is no longer relevant anymore.</p>
<p>If you build a website with .jsp as the suffix to all URLs, and then a couple of years later your boss wants to re-write the website in python, does that mean you change all URLs to be .py, and setup mass url re-writing schemes to handle the old URLs? No, this would be a nightmare. Protect your future self by completely leaving the actual technology used to build the website outside of the URL.</p>
<p>Another bonus is that these URLs also end up being more SEO friendly!</p>
<h3>Use a JavaScript Framework (maybe)</h3>
<p>If you are building an AJAX heavy website such as GMail or Facebook, use a JavaScript framework. This is not relevant for many sites that simply use JavaScript to provide some enhanced functionality, but for websites that are heavily dependent upon JavaScript and simply cannot function without it.</p>
<p>I&#8217;m not talking about jQuery or Prototype, while those are good libraries that abstract the differences between browsers and provide easy to use functions, they are not built as a comprehensive framework. I&#8217;m suggesting you use a framework like JavaScriptMVC, SproutCore, or Spry. These frameworks can be used in tandem with jQuery, but go much farther in helping you organize and control your JavaScript code.</p>
<p>Watch a <a href="http://javascriptmvc.s3.amazonaws.com/videos/2_0/2_0_demo.htm">demo video</a> of what JavaScriptMVC can do for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2011/01/web-development-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Drag and Drop with jQuery</title>
		<link>http://www.markdeepwell.com/2010/11/multiple-drag-and-drop-with-jquery/</link>
		<comments>http://www.markdeepwell.com/2010/11/multiple-drag-and-drop-with-jquery/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 07:25:15 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Drag and Drop]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=574</guid>
		<description><![CDATA[I took inspiration from David Walsh and updated his Drag and Drop script to be able to handle multiple Drag and Drop sections on one page at the same time. Plus I cleaned it up a bit by adding all the functions to a JavaScript object. As jQuery is my preferred JavaScript library this code [...]]]></description>
			<content:encoded><![CDATA[<p>I took inspiration from David Walsh and updated <a href="http://davidwalsh.name/mootools-drag-ajax">his Drag and Drop script</a> to be able to handle multiple Drag and Drop sections on one page at the same time. Plus I cleaned it up a bit by adding all the functions to a JavaScript object. As jQuery is my preferred JavaScript library this code is using the jQuery version.</p>
<h2><a href="http://www.markdeepwell.com/tutorials/dragndrop.html">Checkout the demo</a></h2>
<pre class="brush: jscript; title: ; notranslate">
/* create object */
function DragNDropList(selector){
  this.list = $(selector);
  this.sortInput = jQuery('#sort_order');

  /* store values */
  this.list.children('li').each(function(){
    var li = jQuery(this);
    li.data('id',li.attr('title')).attr('title','');
  });
  /* sortables */
  var obj = this;
  this.list.sortable({
    opacity: 0.7,
    update: function(){
      obj.submit();
    }
  });
  this.list.disableSelection();
}

/* worker function */
DragNDropList.prototype.submit = function(){
  var sortOrder = [];
  this.list.children('li').each(function(){
    sortOrder.push(jQuery(this).data('id'));
  });
  this.sortInput.val(sortOrder.join(','));
  this.request();
}

DragNDropList.prototype.request = function(){
  var obj = this;
  jQuery.ajax({
    success: function(data){
      $(&quot;#status&quot;).text('Saved');
    },
    error: function(){
      $('#status').text('Failed to save sort order').show();
    },
    data: 'sort_order=' + obj.sortInput[0].value,
    dataType: 'json',
    type: 'post',
    url: '/site/update'
  });
};

// init drag-n-drop lists
var list1 = new DragNDropList('#list1');
var list2 = new DragNDropList('#list2');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2010/11/multiple-drag-and-drop-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Documentation</title>
		<link>http://www.markdeepwell.com/2010/10/javascript-documentation/</link>
		<comments>http://www.markdeepwell.com/2010/10/javascript-documentation/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 06:06:15 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Documentation]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Learn JS]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=561</guid>
		<description><![CDATA[A call for better JavaScript documentation has gone out and I am 150% in favour of it. Most of the existing JavaScript code, tutorials, and examples available on the web are just messy mashups that work, but are not code you actually want to use in a website. Therefore I am adding the PromoteJS wordpress [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.promotejs.com/">A call</a> for better <a href="https://developer.mozilla.org/en/JavaScript">JavaScript</a> documentation has gone out and I am 150% in favour of it. Most of the existing JavaScript code, tutorials, and examples available on the web are just messy mashups that work, but are not code you actually want to use in a website. Therefore I am adding the PromoteJS wordpress widget to my blog and I encourage you to do the same.</p>
<div style="text-align:center;">
<a href='https://developer.mozilla.org/en/JavaScript/Guide' title='Learn JavaScript JS'><img src='http://static.jsconf.us/promotejsh.gif' height='150' width='180' alt='Learn JavaScript JS'/></a>
</div>
<p>The world needs better JavaScript documentation.</p>
<p>Let&#8217;s help others and help ourselves by writing and promoting quality JavaScript documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2010/10/javascript-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Hosted jQuery</title>
		<link>http://www.markdeepwell.com/2010/09/google-hosted-jquery/</link>
		<comments>http://www.markdeepwell.com/2010/09/google-hosted-jquery/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 03:38:29 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=547</guid>
		<description><![CDATA[Google provides hosting for many of the most popular JavaScript libraries. I&#8217;m a big fan of jQuery so I&#8217;m going to show you how to use Google&#8217;s hosted version of jQuery and thereby removing resources from your web server and speeding up site performance. Performance can be increased because your user is going to download [...]]]></description>
			<content:encoded><![CDATA[<p>Google provides hosting for many of the most popular <a href="http://code.google.com/apis/libraries/">JavaScript libraries</a>. I&#8217;m a big fan of jQuery so I&#8217;m going to show you how to use Google&#8217;s hosted version of jQuery and thereby removing resources from your web server and speeding up site performance.</p>
<p>Performance can be increased because your user is going to download the jQuery file from Google&#8217;s CDN network and not from your server. Also, it could be even faster if the user visited another website that also uses Google&#8217;s hosted jQuery. If that is the case then your user won&#8217;t need to download it again and will use the exactly same cached version.</p>
<p>There are two ways to do this.</p>
<p>The fastest and simplest is to link directly to the Google&#8217; hosted jQuery file:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>The second approach has more features but there is a slight delay while the jsapi loads the correct version of jQuery. If you want the absolute best performance use the first version.</p>
<p>1) <a href="http://code.google.com/apis/ajaxsearch/signup.html">Signup</a> to get your own API key</p>
<p>2) Add the following code to your layout:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi?key=INSERT-YOUR-KEY&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
google.load(&quot;jquery&quot;, &quot;1.4.2&quot;);

  google.setOnLoadCallback(function() {
    // Put you init code here instead of using $(document).ready()
  });
&lt;/script&gt;
</pre>
<p>You can also specify the latest version of the 1.4 branch:</p>
<pre class="brush: jscript; title: ; notranslate">
google.load(&quot;jquery&quot;, &quot;1.4&quot;);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2010/09/google-hosted-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What Will Web Development Look Like in 5 Years</title>
		<link>http://www.markdeepwell.com/2010/03/what-will-web-development-look-like-in-5-years/</link>
		<comments>http://www.markdeepwell.com/2010/03/what-will-web-development-look-like-in-5-years/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 16:40:45 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Software Tools]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[5 Years]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Future]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=438</guid>
		<description><![CDATA[Developing applications for the web has changed significantly over the last 5 years. Since 2005 the term AJAX has been coined, Ruby on Rails is now an open source web application framework, jQuery was created and has subsequently revolutionized JavaScript development, and now HTML5 is the top buzzword of the day. I believe the next [...]]]></description>
			<content:encoded><![CDATA[<p>Developing applications for the web has changed significantly over the last 5 years. Since 2005 the term AJAX has been coined, Ruby on Rails is now an open source web application framework, jQuery was created and has subsequently revolutionized JavaScript development, and now HTML5 is the top buzzword of the day. I believe the next 5 years will hold just as many improvements for web developers.</p>
<p>I foresee a new framework will be created to make developing fully interactive AJAX applications  as easy as it is to write current MVC applications. Current  frameworks like Ruby on Rails and Symfony provide everything you need to develop a modern application without having to build plumbing infrastructure; however, they do not provide nice components for interactive applications. In addition to a robust server core, this new framework will have   a client side JavaScript component that simplifies the process of building interactive web 2.0 applications. Some critical components would be:</p>
<ul>
<li>Form Validation. Libraries do exist to validate forms in JavaScript,  but they don&#8217;t integrate with the server side form validation. In this new framework you won&#8217;t have to write form validation code twice.</li>
<li>Paginated Lists. Almost all web applications have at least one page where data needs to be searched and listed with pagination. We need to have this same functionality in JavaScript to skip a full page reload and provide local caching of the results.</li>
<li>Animation Library. While script.aculo.us and jQuery have made simple animations and visual effects much easier to do, I believe we can go even farther. Web applications also need to gain that fluidity and soft animations that desktop applications such as Exposé have had for a couple of years.</li>
</ul>
<p>I also see huge resources being directed towards mobile development because ALL current generation smart phones are built for an incredible web browsing experience. As home users have switched from <a href="http://www.canada.com/technology/tech-biz/laptops+dominate+desktop+face+obsolescence/1151512/story.html">desktop computers</a> to <a href="http://www.google.com/trends?q=laptop%2C+desktop">laptop computers</a> in the last few years, people will slowly start switching to hand-held devices for their primary communication and Internet needs. Most likely this will have one primary effect: web frameworks will have a mobile optimized version of the site done automatically. Little to none developer intervention will be required as only resolution, text sizes, and layouts will be modified for the mobile version.</p>
<p>Lastly I see tools and libraries around 2D and 3D drawing elements. Most likely these libraries would be rendering to a <a href="https://developer.mozilla.org/en/Canvas_tutorial">Canvas</a> or a <a href="http://planet-webgl.org/">WebGL</a> element but something better could be created. Both of these are young standards right now that show a lot of promise on delivering the ability to draw pixels directly in a native HTML web page. While they will be used first in simple computer games, I am very interested to see what libraries are created to facilitate these elements being used appropriately inside next generation web applications.</p>
<p>What do you think the next 5 years will bring?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2010/03/what-will-web-development-look-like-in-5-years/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook vs You!</title>
		<link>http://www.markdeepwell.com/2009/12/facebook-vs-you/</link>
		<comments>http://www.markdeepwell.com/2009/12/facebook-vs-you/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 06:31:49 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Facebook App]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=445</guid>
		<description><![CDATA[Have you had the&#8230; how should I describe it&#8230; experience of writing a Facebook application? No? OK, here&#8217;s an introduction to what you can expect. When developing an application you must learn Rule #1 Facebook is the gatekeeper. Everything you do, be it HTML, CSS or JavaScript, is restricted by Facebook. Only the commands, functions, [...]]]></description>
			<content:encoded><![CDATA[<p>Have you had the&#8230; how should I describe it&#8230; <strong>experience</strong> of writing a Facebook application? No? OK, here&#8217;s an introduction to what you can expect.</p>
<p>When developing an application you must learn Rule #1 <strong>Facebook is the gatekeeper</strong>. Everything you do, be it HTML, CSS or JavaScript, is restricted by Facebook. Only the commands, functions, CSS properties, HTML tags etc. that Facebook allows are permissible. If you have an error in your HTML such as an unclosed tag or if you try to use a CSS property that does not exist, Facebook will render a very nice message saying you made an error.</p>
<p>Rule #2 <strong>The never ending cycle</strong>. The Facebook platform is constantly changing and APIs that you are using in your application could disappear one day without any notice. It&#8217;s the life of a Facebook application, working one instant, inexplicably broken the next. Be prepared for irregular maintenance just to keep your application working.</p>
<p>A Facebook Application  lives in the world of Facebook and while it might initially seem  like you&#8217;re developing a standard web application you are not. Rule #3 <strong>You&#8217;re application is on the Facebook web</strong>. It&#8217;s not a regular web application which is a very slight but critical distinction. Facebook has used their powers as the gatekeeper to make modifications to the web. Some HTML tags are allowed, some are not. <a href="http://wiki.developers.facebook.com/index.php/FBJS#FBJS_DOM_Objects">JavaScript has been altered</a> to remove a lot of its power and replace only some of them with Facebook specific functions and even CSS has restrictions. Don&#8217;t expect existing code to function when placed in the Facebook web.</p>
<h3>Additional Caveats</h3>
<ul>
<li>You cannot include any external JavaScript or style sheet files, they must be included in-line. This is so Facebook can parse them and allow only approved commands. Yes it enhances the security of the social networking site as a whole, but it will slow down your development time.</li>
<li>Facebook will filter, compile, and drastically alter your original code. Clicking view-source on a Facebook page with your application will show your JavaScript code mushed into awkward Facebook functions.</li>
</ul>
<p>Do you see that it&#8217;s a bit of a battle of you against the mighty Facebook? Don&#8217;t sweat too much, other developers have persevered and with a few wounds and time you can build and maintain a successful Facebook application. Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2009/12/facebook-vs-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UpcomingHoliday.com Now with Geolocation</title>
		<link>http://www.markdeepwell.com/2009/12/upcomingholiday-com-now-with-geolocation/</link>
		<comments>http://www.markdeepwell.com/2009/12/upcomingholiday-com-now-with-geolocation/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 06:27:40 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Web Application]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Geolocation]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=440</guid>
		<description><![CDATA[UpcomingHoliday.com has been updated and now includes geolocation support. If your browser supports it your country should automatically find and select your country. If not, it will fall back to IP based country lookup. Geolocation is a HTML 5 feature that is supported by Safari on the iPhone 3.0 OS, Firefox 3.5 and Google Chrome. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://upcomingholiday.com">UpcomingHoliday.com</a> has been updated and now includes <a href="http://dev.w3.org/geo/api/spec-source.html">geolocation</a> support. If your browser supports it your country should automatically find and select your country. If not, it will fall back to IP based country lookup. Geolocation is a HTML 5 feature that is supported by Safari on the iPhone 3.0 OS, Firefox 3.5 and Google Chrome.</p>
<p>UpcomingHoliday.com is an application that tells you what and when your <a href="http://upcomingholiday.com">next federal holiday</a> is. Currently it&#8217;s available for people in: Australia, Canada, France, Germany, India,  Nigeria, United Kingdom and United States.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2009/12/upcomingholiday-com-now-with-geolocation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning WebGL</title>
		<link>http://www.markdeepwell.com/2009/11/learning-webgl/</link>
		<comments>http://www.markdeepwell.com/2009/11/learning-webgl/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 21:22:15 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=366</guid>
		<description><![CDATA[If you&#8217;re interested in programming graphics on the web I recommend subscribing to Planet WebGL; it has a lot of great tutorials and instructional material for learning how to program graphics in a web environment. WebGL is technically a JavaScript binding to OpenGL ES 2.0. If you already know OpenGL ES and JavaScript, you should [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re interested in programming graphics on the web I recommend subscribing to <a href="http://planet-webgl.org/">Planet WebGL</a>; it has a lot of great tutorials and instructional material for learning how to program graphics in a web environment.</p>
<p>WebGL is technically a JavaScript binding to OpenGL ES 2.0. If you already know OpenGL ES and JavaScript, you should be able to pick it up pretty quickly. If you know JavaScript but not OpenGL and are in a web development career, I encourage you to look into WebGL because it could be one key component of interactive web applications in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2009/11/learning-webgl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Intro to Objects in JavaScript</title>
		<link>http://www.markdeepwell.com/2009/10/intro-to-objects-in-javascript/</link>
		<comments>http://www.markdeepwell.com/2009/10/intro-to-objects-in-javascript/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 06:23:03 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=317</guid>
		<description><![CDATA[Despite what you might think, JavaScript supports programming in full object oriented style including inheritance, encapsulation and polymorphism. But before we dive into all those topics I&#8217;m going to start with the basics and demonstrate how to create and use a simple JavaScript object. Lets say you have a web application that needs to track [...]]]></description>
			<content:encoded><![CDATA[<p>Despite what you might think, JavaScript supports programming in full object oriented style including inheritance, encapsulation and polymorphism. But before we dive into all those topics I&#8217;m going to start with the basics and demonstrate how to create and use a simple JavaScript object.</p>
<p>Lets say you have a web application that needs to track how long an AJAX request took. If you were writing it in Ruby, PHP or Python you&#8217;d have a timer object that you can start() and stop() and a seconds() method to get the number of seconds that passed between calling the first two methods.</p>
<p>To build this in JavaScript we first create our constructor:</p>
<pre class="brush: jscript; title: ; notranslate">
Timer = function() {
  var seconds_passed = 0;
}
</pre>
<p>Here we are creating a Timer object with a private  seconds_passed variable. To create this object we we simply create a new timer:</p>
<pre class="brush: jscript; title: ; notranslate">
var elapsed_timer = new Timer();
</pre>
<p>This timer object now needs some public methods. We can attach a public method by using this.method_name:</p>
<pre class="brush: jscript; title: ; notranslate">
Timer = function() {
  var seconds_passed = 0;

  this.start = function() {
    // implementation here
  }
}
</pre>
<p>Our Timer class now has a start() function. Additional public methods can be added in the same way.</p>
<p>To add a private method, don&#8217;t define it with the <em>this</em> keyword but instead create a regular function inside the class:</p>
<pre class="brush: jscript; title: ; notranslate">
Timer = function() {
  function increment() {
    // implementation of private method here
  }
}
</pre>
<p>Now we have a Timer object with a public start method and a private increment method. The rest of the class is fairly simple, so lets jump to the finished solution.</p>
<h3>Complete Example</h3>
<pre class="brush: jscript; title: ; notranslate">
Timer = function() {
  var timeout_id = null;
  var seconds_passed = 0;

  this.start = function() {
    increment();
  }

  this.stop = function() {
    clearTimeout(timeout_id);
    timeout_id = null;
  }

  this.seconds = function() {
    return seconds_passed;
  }

  function increment() {
    seconds_passed++;

    timeout_id = window.setTimeout(
      function() {
        increment();
      }
      , 1000
    );
  }
}

var elapsed_timer = new Timer();
elapsed_timer.start();

// do some stuff

elapsed_timer.stop();
alert(elapsed_timer.seconds());
</pre>
<p>There you have it. A simple JavaScript timer to keep track of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2009/10/intro-to-objects-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firebug: The JavaScript Debugger</title>
		<link>http://www.markdeepwell.com/2009/10/firebug-the-javascript-debugger/</link>
		<comments>http://www.markdeepwell.com/2009/10/firebug-the-javascript-debugger/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 05:08:26 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Software Tools]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[Firefox Extension]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.markdeepwell.com/?p=291</guid>
		<description><![CDATA[JavaScript is a core language of many web developers and a necessary component for any modern web application; therefore having an excellent JavaScript debugger and knowing how to use it effectively is key to fixing bugs faster. Fixing bugs faster also makes you a happier software developer! I recommend Firebug, which is a JavaScript debugger, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">JavaScript is a core language of many web developers and a necessary component for any modern web application; therefore having an excellent JavaScript debugger and knowing how to use it effectively is key to fixing bugs faster. Fixing bugs faster also makes you a happier software developer!</p>
<p style="text-align: left;">I recommend <a href="http://getfirebug.com/">Firebug</a>, which is a JavaScript debugger, a real-time HTML, CSS, DOM, and JavaScript editor, and a network monitor.</p>
<h1 style="text-align: left;">Logging</h1>
<p>One of the most useful features are the <a href="http://getfirebug.com/console.html">logging functions</a> through console.log which can simply be used to output a string or object:<br />
<code><br />
console.log('Testing log output: ', myObject);<br />
</code><br />
This will output your message and the full object available for inspection in the Firebug console tab. In addition to console.log, there is also console.warn, console.error, and more. See the <a href="http://getfirebug.com/console.html">Firebug documentation</a> for more info.</p>
<p>Be careful to remove the statements from your code before deploying it, because your users won&#8217;t have Firebug installed, and JavaScript will then fail when it tries to output to the console object. Also, you certainly don&#8217;t want users to see your debug output.</p>
<div id="attachment_297" class="wp-caption alignnone" style="width: 498px"><img class="size-full wp-image-297 " title="firebug logger" src="http://www.markdeepwell.com/wp-content/uploads/2009/10/firebug-logger.jpg" alt="firebug logger" width="488" height="164" /><p class="wp-caption-text">console.log in action</p></div>
<h1>Breakpoints</h1>
<p>Pausing scripts to investigate the system at a current point in time can be very valuable in solving bugs. To use the breakpoint feature click just to the left of a JavaScript line. This will set a breakpoint and make a red dot appear.</p>
<p>You can also add a conditional breakpoint by right clicking on a line number. Now the program will only pause under your specified condition.</p>
<div id="attachment_296" class="wp-caption alignnone" style="width: 405px"><img class="size-full wp-image-296 " title="firebug breakpoint" src="http://www.markdeepwell.com/wp-content/uploads/2009/10/20091012-e798upemuhaiy18esaxmpheqtm.jpg" alt="firebug breakpoint" width="395" height="163" /><p class="wp-caption-text">Setting a breakpoint</p></div>
<h1>JavaScript Errors</h1>
<p>Firebug will print out JavaScript errors with the corresponding file and line number. An absolute must for any JavaScript development.</p>
<div id="attachment_305" class="wp-caption alignnone" style="width: 525px"><img class="size-full wp-image-305" title="firebug javascript error" src="http://www.markdeepwell.com/wp-content/uploads/2009/10/firebug-javascript-error.jpg" alt="firebug javascript error" width="515" height="157" /><p class="wp-caption-text">A JavaScript Error</p></div>
<p>Those are the key feature I use most often, but there are many more <a href="http://getfirebug.com/js.html">JavaScript features in Firebug</a>, including stack traces, watching expressions, profiling and viewing events.</p>
<p><a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Download Firebug now</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.markdeepwell.com/2009/10/firebug-the-javascript-debugger/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

