<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ajax Ramble</title>
	<atom:link href="http://ajaxramble.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajaxramble.wordpress.com</link>
	<description>ramble:  to go where one pleases; to wander</description>
	<lastBuildDate>Fri, 03 Oct 2008 19:45:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ajaxramble.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ajax Ramble</title>
		<link>http://ajaxramble.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ajaxramble.wordpress.com/osd.xml" title="Ajax Ramble" />
	<atom:link rel='hub' href='http://ajaxramble.wordpress.com/?pushpress=hub'/>
		<item>
		<title>jQuery and Microsoft</title>
		<link>http://ajaxramble.wordpress.com/2008/10/03/jquery-and-microsoft/</link>
		<comments>http://ajaxramble.wordpress.com/2008/10/03/jquery-and-microsoft/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 19:43:24 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Asp.net Ajax]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=77</guid>
		<description><![CDATA[I have writen previously saything that I intend to look at jQuery as an alternative to the Asp.net ajax framework, now I cant because Microsoft have just announced that jQuery is about to be release as part of Visual studio! jQuery is an open source javascript library which makes it simple to transverse and manipulate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=77&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have writen previously saything that I intend to look at jQuery as an alternative to the Asp.net ajax framework, now I cant because Microsoft have just announced that jQuery is about to be release as part of Visual studio!</p>
<p><span id="more-77"></span>jQuery is an open source javascript library which makes it simple to transverse and manipulate the dom tree, and provides event handling and animiations, as well as a large community for support and plugins.  I will provide a few examples in an upcoming blog. Developers have been asking Microsoft for jQuery like dom processing, and instead of Microsoft writing their own, they decided to use jQuery as is.</p>
<p>This is great news, and the first time (as far as I know) that Microsoft have done this and embraced open source technology as part of its product platform.  I personally think this is a great move, one of the things I like about java is the fact the community make use of all the open source software out there, not try to compete with them, now is Microsoft adopting the same pattern?</p>
<p>Microsft intend to provide Visual Studio intellisense, provide support, and in the future will provide Asp.net toolbox controls which use JQuery and server side helper methods for asp.net MVC.</p>
<p>Check out: <a title="jQuery blog" href="http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/">jQuery blog</a>, <a title="Scott Hansleman" href="http://www.hanselman.com/blog/jQuerytoshipwithASPNETMVCandVisualStudio.aspx">Scott Hanselman&#8217;s Blog</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=77&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/10/03/jquery-and-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>Google Chrome &#8211; New kid on the block</title>
		<link>http://ajaxramble.wordpress.com/2008/09/21/google-chrome-new-kid-on-the-block/</link>
		<comments>http://ajaxramble.wordpress.com/2008/09/21/google-chrome-new-kid-on-the-block/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 22:38:46 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[browsers]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=64</guid>
		<description><![CDATA[Google has recently released its new browser, called Chrome which is aimed to rival Microsoft&#8217;s Internet Explorer.  I have been using it for a couple of days now, and here is my thoughts. Chrome looks slick, Google have dared to make their browser look that bit smarter than the competition, which is simple to use, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=64&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Google has recently released its new browser, called Chrome which is aimed to rival Microsoft&#8217;s Internet Explorer.  I have been using it for a couple of days now, and here is my thoughts.</p>
<p><span id="more-64"></span></p>
<p>Chrome looks slick, Google have dared to make their browser look that bit smarter than the <span class="dicColor">competition</span>, which is simple to use, and yet very familiar.  However it does feel a little light on features compared to the other browsers in the market, e.g. you cannot organise your bookmarks.  But then this is just a beta version of the browser and I&#8217;m sure those standard browser features will be in the finished release.  I can see google chrome acting as a continer for multiple types of applications.</p>
<p>The first thing you notice about chrome is just how fast it is, is is due in part to its new open source javascript engine called V8.  V8 is a new JavaScript engine specifically designed for fast execution of large JavaScript applications. In several benchmark tests, according to Google, V8 is many times faster than JScript (in Internet Explorer), SpiderMonkey (in Firefox), and JavaScriptCore (in Safari). If your web application is bound by JavaScript execution speed, using V8 instead of your current JavaScript engine is likely to improve your application&#8217;s performance. How big the improvement is depends on how much JavaScript is executed and the nature of that JavaScript. For example, if the functions in your application tend to be run again and again, the performance improvement will be greater than if many different functions tend to run only once.</p>
<p>Google believes as we create more complex javascript applications in our browsers, there is a need for a faster javascript runtime which none of the competition can provide.  Google believe that in the future Chrome may become more than a browser, they describe it as a platform for running web applications.  Could this be the seed of the first online operating system?</p>
<p>There are a number of features which make this browser stand out (although IE* will rival some of them),</p>
<ul>
<li>the &#8220;Omnibar&#8221; allows you to use one bar for everything including the address bar, search box, history etc.</li>
<li>Every time you create a new tab you get a number of thumnails dispalyed which show your most visited sites, bookmarks and recently closed tabs</li>
<li>Dynamic tabs &#8211; this is way cool. You can simply drag a tab out of the browser and create a new instance of the Chrome browser, then can drag tabs between the browsers.  This is great, normally I have a few browsers open, and its a great idea to be able to organise your tabs in this way.</li>
<li>Incognito mode &#8211; private browsing, np trace that you have been on a site &#8211; not sure why you would need this <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>Simple downloads, now you don&#8217;t have another window popping up every time you download a file, it is now part of the main browser.</li>
</ul>
<p>I really like this browser, however it has a way to go before it becomes my main browser.  I am a fan of FireFox because of its extensibility, I would miss my Delicious bookmarks, my developer tools, my colour picker &amp; CSS helpers (to name but a few plugins). However I believe my wife will love this browser simply due to its speed.</p>
<p>Google is on to a winner here, I believe, with a bit of work,  it will eat into the Internet Explorer market share, and the Firefox market share to a slightly lesser extent.  I know that it is far from perfect, bookmark management, plugins and addons being the big things missing for me, but then again this is just a piece of beta software&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=64&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/09/21/google-chrome-new-kid-on-the-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript Extender Control</title>
		<link>http://ajaxramble.wordpress.com/2008/08/23/javascript-extender-control/</link>
		<comments>http://ajaxramble.wordpress.com/2008/08/23/javascript-extender-control/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 21:41:31 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Asp.net Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=54</guid>
		<description><![CDATA[I am going to create a simple JavaScript extender control which I plan to use on my websites, the control will simply provide a visual clue to the user to which field has the current focus.  This is inspired by Apple&#8217;s Safari browser. Ok, to start lets take a simple bit of JavaScript and a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=54&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am going to create a simple JavaScript extender control which I plan to use on my websites, the control will simply provide a visual clue to the user to which field has the current focus.  This is inspired by Apple&#8217;s Safari browser.</p>
<p><span id="more-54"></span></p>
<p>Ok, to start lets take a simple bit of JavaScript and a bit of field markup.<br />
<code><br />
&lt;script  type="text/javascript"&gt;<br />
function FieldHighlighter(object,highlight){<br />
if(highlight){<br />
object.style.background="#ffffaa";<br />
}else{<br />
object.style.background="#ffffff";<br />
}<br />
}<br />
&lt;/script&gt;<br />
&lt;input type="text" id="txtName" onfocus="FieldHighlighter(this,true);" onblur="FieldHighlighter(this,false);" /&gt;<br />
</code><br />
That’s it, time to go home?  Well, not quite.  In a past life, this is how I would have written JavaScript (and when push comes to shove, I would probably have my first stab of a JavaScript function like this).  My biggest  criticism of this code is that the input control on the page is determining the functionality expressed on the page, and if I have 5 controls on the page, all having similar functionality, I need to markup each control.</p>
<p>This may be prone to error, and if I decide to change how my page will function (e.g. add an effect when the mouse rolls over the control), I will now need to update each control, on each page where my new functionality is required.  Now if only we had a single place to put the functionality…</p>
<p>I have written a standard JavaScript class to provide an extender for a form control.  The first thing you will notice is there is a LOT more code to write, first I create the object, then add the OnInit method to the objects prototype, then I have to do all the event wire up.<br />
<code><br />
function FieldFocusExtender(highlightStyle,unHighlightStyle,controlToExtend){<br />
this.HighlightStyle=highlightStyle;<br />
this.UnHighlightStyle=unHighlightStyle;<br />
this.ControlToExtend=controlToExtend;<br />
this.OnInit();<br />
};<br />
FieldHighlighterExtender.prototype.OnInit = function(){<br />
var control = document.getElementById(this.ControlToExtend);<br />
var that = this;<br />
removeHighlight();<br />
if(control!=null){<br />
control.addEventListener('focus',highlight,true)<br />
control.addEventListener('blur',removeHighlight,true)<br />
}else{<br />
//Throw exception<br />
var err = new Error();<br />
err.message = "ControlToExtend cannot be resolved.";<br />
err.name = "ArgumentException";<br />
throw err;<br />
}<br />
function highlight(object){<br />
control.style.background=that.HighlightStyle;<br />
}<br />
function removeHighlight(object){<br />
control.style.background=that.UnHighlightStyle;<br />
}<br />
}<br />
</code><br />
Why bother?  Well, I have now written all my implementation code in one place, I have written code that has been tested in isolation of my page, therefore when I add this extender to my page I can be sure that the extender will function as expected.   Sounds like good programming practice, doesn&#8217;t it?  Oh yea, and this is how easy is it to use my extender:<br />
<code><br />
&lt;input type="text" id="txtName"  /&gt;<br />
…<br />
&lt;script type="text/javascript"&gt;<br />
var extender = new FieldFocusExtender("fieldFocusOn","fieldFocusOff","txtName");<br />
&lt;/script&gt;<br />
</code><br />
I want to point out a few things about the code before I continue. …</p>
<ul>
<li>I updated the class to use CSS rather than just changing the background colour &#8211; makes my textboxes prettier!</li>
<li>I have styled the methods to look a similar to the methods I use server side, e.g. OnInit.  This introduces landmarks a server side developer should recognise.</li>
<li>You will notice a  strangle looking line &#8220;var that=this;&#8221;, let me explain:  when you create a function inside another function as I have done above, the variable this is bound  to the global object rather than the outer function (as would be expected).  This is a bug in JavaScript, and to get around this bug, the convention is to create a variable called &#8216;that&#8217;, which will work in the inner functions.</li>
</ul>
<p>And finally, I will update this control to use some of the features of the Asp.net Ajax framework:</p>
<p><code><br />
///Create a namespace<br />
Type.registerNamespace("AjaxRamble.Controls");<br />
//Create the class<br />
AjaxRamble.Controls.FieldFocusExtender=function(highlightStyle,unHighlightStyle,controlToExtend,hasFocus){<br />
AjaxRamble.Controls.FieldFocusExtender.initializeBase(this);<br />
this._focusedStyle=highlightStyle;<br />
this._unFocusedStyle=unHighlightStyle;<br />
this._controlToExtend=controlToExtend;<br />
this._hasFocus=false;<br />
this.OnInit();<br />
this.set_hasFocus(hasFocus||null);<br />
}<br />
//Create the prototype<br />
AjaxRamble.Controls.FieldFocusExtender.prototype ={<br />
get_focusedStyle:function(){<br />
return this._focusedStyle;<br />
},<br />
set_focusedStyle:function(value){<br />
this._focusedStyle=value;<br />
},<br />
get_unFocusedStyle:function(){<br />
return this._unFocusedStyle;<br />
},<br />
set_unFocusedStyle:function(value){<br />
this._unFocusedStyle=value;<br />
},<br />
get_controlToExtend:function(){<br />
return this._controlToExtend;<br />
},<br />
set_controlToExtend:function(value){<br />
this._controlToExtend=value;<br />
},<br />
get_hasFocus:function(){<br />
return this._hasFocus;<br />
},<br />
set_hasFocus:function(value){<br />
if(value===true){<br />
$get(this._controlToExtend).focus();<br />
this._hasFocus=value;<br />
}else if(value===false){<br />
if(this._hasFocus){<br />
$get(this._controlToExtend).blur();<br />
this._hasFocus=value;<br />
}<br />
}<br />
},<br />
OnInit: function(){<br />
var control = $get(this._controlToExtend);<br />
var that = this;<br />
if(control!=null){<br />
control.addEventListener('focus',highlight,true)<br />
control.addEventListener('blur',removeHighlight,true)<br />
}else{<br />
//Throw exception<br />
var err = new Error();<br />
err.message = "ControlToExtend cannot be resolved.";<br />
err.name = "ArgumentException";<br />
throw err;<br />
}<br />
if(!that._hasFocus){<br />
removeHighlight();<br />
}else{<br />
highlight()<br />
}<br />
function highlight(){<br />
Sys.UI.DomElement.removeCssClass(control,that._unFocusedStyle);<br />
Sys.UI.DomElement.addCssClass(control,that._focusedStyle);<br />
that._hasFocus=true;<br />
}<br />
function removeHighlight(){<br />
Sys.UI.DomElement.removeCssClass(control,that._focusedStyle);<br />
Sys.UI.DomElement.addCssClass(control,that._unFocusedStyle);<br />
that._hasFocus=false;<br />
}</code><code>}<br />
}<br />
//Register the class with the ajax runtime<br />
AjaxRamble.Controls.FieldFocusExtender.registerClass("AjaxRamble.Controls.FieldFocusExtender");<br />
</code><br />
Now that’s what I call code bloat, my 4 line function has turned into a 60+ line monster!!</p>
<p>I have taken my extender code I wrote in my second code example, and transformed it into a class which can be wrapped in a server control in the Asp.net Ajax framework.   Looks pretty similar to my second example doesn’t it,   well it should, it uses the basic OO pattern of the second example, with a few ajax library calls added for good measure.   And (for now) we use the new object in a similar manner as before&#8230;<br />
<code><br />
&lt;input type="text" id="txtName"  /&gt;<br />
…<br />
&lt;script type="text/javascript"&gt;<br />
var extender2 = new AjaxRamble.Controls.FieldFocusExtender("fieldFocusOn","fieldFocusOff","txtName");<br />
&lt;/script&gt;<br />
</code><br />
The third code example shows the 4 steps needed to build a class in Asp.net ajax:</p>
<p>1. Create the namespace &#8211; Simply define the namespace to be used by ajax framework</p>
<p>2. Create the class &#8211; Standard JavaScript pattern.  There is a method call to initialise base ( AjaxRamble.Controls.FieldFocusExtender.initializeBase(this);), we add this by default to all the asp.net ajax classes becasuse we do not define the object inheritance as part of the constructor function, instead t is defined later (see step 4)</p>
<p>3. Decorate the prototype with the methods (define the object interface)  &#8211; Standard JavaScript pattern.  Note, the use of the pattern get_x and set_x(value).  This pattern for patterns is used by the asp.net ajax framework to associate webcontrol properties with the properties on the JavaScript class.  More on that in  another blog.</p>
<p>4. Register the class with the ajax runtime &#8211; defines the class within the ajax framework.  Where a class inherits from another class, the base class is specified in this method, e.g. AjaxRamble.Controls.FieldFocusExtender.registerClass( &#8220;AjaxRamble.Controls.FieldFocusExtender&#8221;,AjaxRamble.Controls.BaseExtender );</p>
<p>So, after completing this, I have got to ask, is it worth it?  I have taken a simple JavaScript function, and transformed it into a monster, but in doing so I have a new extender object which I can test once, saving some testing in the applications which I use it.  I have one place to ensure my code works cross browser (not shown here), and I have the ability to add functionality that does not exist in the current html controls once (the hasFocus() property in my example, which is not available to standard html controls).   So yes, I believe this approach to JavaScript works well (although some may argue the JavaScript implementation is not the greatest &#8211; but that’s for another day).</p>
<p>The Asp.net ajax extensions are not as feature rich as most of the other JavaScript frameworks,  it is more bloated than some of the other libraries, and because it is a Microsoft product may be poo-pooed by some development communities.  However, I work in a company who&#8217;s developers are all &#8220;server-side&#8221; Asp.net application developers, all the development staff are comfortable with C#, but most believe JavaScript is a dirty word due to misunderstanding the language.  I like the Microsoft ajax implementation because it has familiar landmarks (methods, constructs and objects) which server-side developers  can easily get to grips with, also it can be wrapped with server side controls, allowing developers to use the features without worrying about the client side implementation.</p>
<p>On the other hand &#8211; I have been developing web applications for 8+ years, using classic ASP, JSP, PHP and Asp.net, so I am in the fortunate position where I don&#8217;t need a server-side tag to add a client side feature, be it field validation or manipulating the DOM.  Because of this I hope to look at jQuery as an alternative to Asp.net ajax extensions for my own applications, giving me a chance to compare and contrast the two libraries.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/54/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/54/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=54&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/08/23/javascript-extender-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript: The Good Parts</title>
		<link>http://ajaxramble.wordpress.com/2008/08/13/javascript-the-good-parts/</link>
		<comments>http://ajaxramble.wordpress.com/2008/08/13/javascript-the-good-parts/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 20:02:56 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=40</guid>
		<description><![CDATA[The King is dead long live the King!! For a long time there was only one book you should buy if you wanted to know everything there was to know about JavaScript, and that was David Flanagan&#8217;s weighty tomb &#8220;Javascript: The definitive guide&#8220;.  However this book, now in its 5th edition, has become a bit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=40&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://oreilly.com/catalog/covers/9780596517748_cat.gif"><img class="alignleft" src="http://oreilly.com/catalog/covers/9780596517748_cat.gif" alt="" width="180" height="236" /></a></p>
<blockquote><p>The King is dead long live the King!!</p></blockquote>
<p>For a long time there was only one book you should buy if you wanted to know everything there was to know about JavaScript, and that was David Flanagan&#8217;s weighty tomb &#8220;<a href="http://oreilly.com/catalog/9780596101992/index.html">Javascript: The definitive guide</a>&#8220;.  <span id="more-40"></span></p>
<p>However this book, now in its 5th edition, has become a bit of a monster, the first half of the book covering everthing from langage structure to creating modules, from scripting Java to scripting the browsers Document Object Model (DOM).  The second half of the book is an api reference for language.</p>
<p>Now a newcomer has entered the ring to fight for the title of &#8220;<em>THE</em> JavaScript book&#8221;.  <a href="http://oreilly.com/catalog/9780596517748/index.html">Javascript: The Good Parts</a> is written by <a href="http://www.crockford.com/">Douglas Crockford</a>, a Senior Software Architect at Yahoo, and is described as one of the most knowledgable people on the planet when it comes to JavaScript.  Douglas is also the author of JSON, and object notation language for javascript, which I will cover in another article.</p>
<p>The book could not be more different form the Definitive Guide, weighing in at only about 150 pages it is a lightweight compared to Flanagan&#8217;s Book.  The content is also somewhat different.  Out goes anything not relating to Javascript <em>language</em>: DOM, Java, xml, browsers, cookies etc, and instead Crockfords book concentrates on JavaScript itself, detailing objects, methods, arrays and regular expressions. The book is an easy read, replacing lengthy descriptions of a feature with a succinct  &amp; coherrent desctiption that explains the features, with an example usually provided to hammer home the description.</p>
<p>As the title suggests the books deals with what Crockford  describes as the &#8220;Good Parts&#8221;, but to know the Good parts one most also know what is bad (sounds like a quote from some bad movie).  Crockford also deals with this by descibing what is generally bad about the language, and how to use the language itself to overcome some of these bad (and awful) features, e.g. using javascript modules to truely encapsulate objects and how to ensure there is less reliance on global variables.</p>
<p>This book is not really a beginners book, I cannot imagine picking up this book to learn how to hover over an image!  This book is intended to teach web developers how to write JavaScript, not just to do <em>&#8220;this</em> or <em>that&#8221;</em>, and I believe it would be a great boon to anybody starting to think about creating their own JavaScript libraries.</p>
<p>My last word must be, I wish more authors would take a leaf out of Crockfords book (pun intended),  his style of writing is to the point without the need of the verbosity that many writers feel they need to make their books thicker.  Not only does it take less time to read (and therefore I can spend more time playing with the technology), but also it saves a tree or two!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=40&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/08/13/javascript-the-good-parts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>

		<media:content url="http://oreilly.com/catalog/covers/9780596517748_cat.gif" medium="image" />
	</item>
		<item>
		<title>10 things I didn’t know about Javascript &#8211; Part 3 &#8211; Structure.</title>
		<link>http://ajaxramble.wordpress.com/2008/08/09/10-things-i-didn%e2%80%99t-know-about-javascript-part-3-structure/</link>
		<comments>http://ajaxramble.wordpress.com/2008/08/09/10-things-i-didn%e2%80%99t-know-about-javascript-part-3-structure/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 20:59:55 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=8</guid>
		<description><![CDATA[This part concludes my article on &#8220;10 things&#8230;&#8221;, you can find the other parts of the article by following the links below: 10 things&#8230; (Part 2 &#8211; Object Orientation) 10 things&#8230; (Part 1 &#8211; Exception Management) This part finishes my list of things I didn’t know, it covers a few miscellaneous features about the structure [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=8&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This part concludes my article on &#8220;10 things&#8230;&#8221;, you can find the other parts of the article by following the links below:</p>
<ul>
<li><a title="10 things I didn’t know about Javascript - Part 2 - Object Orientation" href="http://ajaxramble.wordpress.com/2008/07/22/10-things-i-didn%E2%80%99t-know-about-javascript-part-2-object-orientation/">10 things&#8230; (Part 2 &#8211; Object Orientation)</a></li>
<li><a title="10 things I didn’t know about Javascript - Part 1 - Exception Management" href="http://ajaxramble.wordpress.com/2008/07/09/10-things-i-didnt-know-about-javascript-part-1-exceptions/">10 things&#8230; (Part 1 &#8211; Exception Management)</a></li>
</ul>
<p>This part finishes my list of things I didn’t know, it covers a few miscellaneous features about the structure of javascript which I feel are important to get the most out ofthe language.</p>
<p><span id="more-8"></span></p>
<h2>7. Properties are stored in an array</h2>
<p>Javascript is a very simple structured language, a javasctipt object stores its properties as an associative index, that’s an array which is accessed via an associated key rather than index integer &#8211; in a similar manner to a Hashtable or Dictionary. The example below shows a simple class, and a method to iterate through the classes properties. Note, in the example below, ALL properties are displayed, including methods (the Guitarist object is detailed in part 2).</p>
<p><code><br />
//Create the object<br />
var steve = new Guitarist(1,”Steve Vai”,”10000″,”Lead”);<br />
// Iterate through the properties<br />
for (var propertyName in steve) {<br />
alert(propertyName + ": " + steve[propertyName]);<br />
}<br />
</code></p>
<p>Of course we can also do the opposite, assigning a value to a object using the name of the property as the index key, which we will see in point 8.</p>
<p>You can see examples of this when in snippets of javasctipt which deal with the DOM, e.g. it is common to see document.forms['myForm'], to refer to the form object on a web page, which is equivalent to document.forms.myForm.</p>
<p>Comparing the associative array to a hashtable is not exactly accurate, the arrays can only use a string as the key, rather than an object (which you can do with &#8220;proper&#8221; hashtables) &#8211; of course if the object produced a hash in the toString()</p>
<h2>8. Dynamic Types</h2>
<p>Dynamic typing is a feature where the type checking is done at runtime, rather than the compiler doing it when the code is being, compiled. This provides us with a very flexible framework for building applications. Of course, &#8220;with great power comes great responsibility&#8221;, with dynamic types you loose the *safety net* of a statically typed language, you do not know until runtime if an object is built correctly, whereas a statically typed language provides feedback on errors well before an application is run.</p>
<p>Ok, what does all this waffle mean? Dynamic types allow us to add methods at runtime, in fact we can create objects with properties and methods at runtime.</p>
<p><code><br />
// Dynamic Drummer<br />
var lars = new Object();<br />
lars.name="Lars Ulrich";<br />
lars.play=function(){<br />
return "dum deddy dum dum crash";<br />
}<br />
</code></p>
<p>Or we can take a type we have created previously and extend it at runtime</p>
<p><code><br />
//Dynamic Method<br />
var zakk = new Musician(1,"Zakk Wylde","10000");<br />
zakk.play=function(){<br />
return "...pentatonic madness..."<br />
}<br />
</code></p>
<p>I would suggest not building objects at runtime, as in the first example, it seems far too ad-hoc and prone to error, if a fully fledged object is required, you should use the prototype as in the previous part of this article. However I think extending a single instance of a class with a method could prove useful, or even extend all they objects of a specific type could be useful at runtime(by extending the objects prototype).</p>
<h2>9. Duct Typing</h2>
<p>Duck typing is a variation of Dynamic Types in which an object&#8217;s current methods and properties determines its type, rather than its inheritance from an interface or class.</p>
<blockquote><p>&#8220;If it walks like a duck and quacks like a duck, I would call it a duck.&#8221;, James Whitcomb Riley</p></blockquote>
<p>In Javascript, types are checked at runtime, where as statically typed languages check the types at compile time, and it is the runtime type checking which allows us to duck type in JavaScript. So what does this all mean? Answer, duck typing allows an object to be passed in to a method that expects a certain type even if it doesn’t inherit from that type. All it has to do is support the methods and properties the method will call.</p>
<p>I&#8217;m not sure how I plan to use Duck Typing yet &#8211; I just think it is a neat feature.</p>
<h2>10. Javascript Frameworks</h2>
<p>And finally… I only discovered recently that there were JavaScript frameworks have been released to make the whole experience of developing with JavaScript simpler, or more familiar at least. My main focus will be using the Asp.Net ajax extensions because that’s what I use in work, however there are a lot more powerful, and fully featured extensions out there.</p>
<ul>
<li><a href="http://openrico.org/">Rico</a></li>
<li><a href="http://developer.yahoo.com/yui/">Yahoo User Interface Library</a></li>
<li><a href="http://www.prototypejs.org/">Prototype</a></li>
<li><a href="http://qooxdoo.org/">Qooxdoo</a></li>
<li><a href="http://www.dojotoolkit.org/">Dojo</a></li>
<li><a href="http://mootools.net/">MooTools</a></li>
<li><a href="http://jquery.com/">jQuery</a></li>
<li><a href="http://script.aculo.us/">script.aculo.us</a></li>
<li><a href="http://www.asp.net/ajax/">Asp.net Ajax</a></li>
<li><a href="http://labs.adobe.com/technologies/spry/home.html">Spry</a></li>
<li><a href="http://dedchain.dustindiaz.com/">DED|Chain</a></li>
<li><a href="http://mochikit.com/">Mochikit</a></li>
</ul>
<p>I guess all these hope to empower us developers, to aid us creating Web 2.0, with such features as simplified DOM scripting, Cross-Browser compatibility, Ajax functionality and control galleries, it seems silly not to use them. Of course all these great features do come with trade offs, the main one being download speed (some less featured frameworks having faster download speed), oh yea, then you need to learn how to use the libraries. Have fun trying to select a framework, you may get a few tips here, but I think the best option is to pick one or two and play with them.</p>
<p>I hope to spend some time playing with jQuery, because it looks pretty simple to use and I could find a lot of controls that are implemented with it. It will be interesting to see how Asp.net Ajax and jQuery &#8220;Co-habituate&#8221;.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=8&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/08/09/10-things-i-didn%e2%80%99t-know-about-javascript-part-3-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>10 things I didn’t know about Javascript &#8211; Part 2 &#8211; Object Orientation</title>
		<link>http://ajaxramble.wordpress.com/2008/07/22/10-things-i-didn%e2%80%99t-know-about-javascript-part-2-object-orientation/</link>
		<comments>http://ajaxramble.wordpress.com/2008/07/22/10-things-i-didn%e2%80%99t-know-about-javascript-part-2-object-orientation/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 21:29:38 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=7</guid>
		<description><![CDATA[Hi again, here is part two of a three part series about Javascript, you can find part one of the series here.  This time I will look at three more items around how to apply object orientated principles to javascript.  I always thought Javascript and &#8220;proper programming&#8221; went together like fish and strawberry jelly, however [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=7&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi again, here is part two of a three part series about Javascript, you can find part one of the series <a href="http://ajaxramble.wordpress.com/2008/07/09/10-things-i-didnt-know-about-javascript-part-1-exceptions/">here</a>.  This time I will look at three more items around how to apply object orientated principles to javascript.  I always thought Javascript and &#8220;proper programming&#8221; went together like fish and strawberry jelly, however how I was wrong, Javascript is a  elegant scripting language, and pretty flexible at the same time.   I think I just needed to get over the association with auto-generated javascript used to create rollover animations and simple validation functions on sites around 5 years ago.  And lets not forget all the associated browser compatibility issues (many of which unfortunately still remain) .</p>
<p>OK enough of my musings, the first thing to check out is how to create a class using Javascript.</p>
<p><span id="more-7"></span></p>
<h2>4.  You can create classes in Javascript</h2>
<p><code><br />
function Musician(id, name, salary){<br />
//public<br />
this.Id=id;<br />
this.Name=name;<br />
//private<br />
var _salary = salary;<br />
var _rehabDays = 0;<br />
//public methods<br />
this.InRehab=function(daysInRehab){<br />
if(arguments[0]==null){<br />
_rehabDays++;<br />
}else{<br />
_rehabDays = _rehabDays + daysInRehab;<br />
}<br />
}<br />
this.CalculateBonus = function(){<br />
var bonusRate = 0.05;<br />
if(IsGoodEmployee()){<br />
bonusRate=bonusRate + 0.05;<br />
}<br />
return _salary * bonusRate;<br />
}<br />
//private methods<br />
IsGoodEmployee = function(){<br />
if(_rehabDays&lt;5){<br />
return true;<br />
}else{<br />
return false;<br />
}<br />
}<br />
}<br />
</code><br />
A javascript function can act in one of two ways,</p>
<p>1. var stevie = Musician()                //as a procedural function declaration<br />
2. var joe = new Musician();        //as a constructor</p>
<p>Generally a function will simply return a variable &#8211; in the case above an undefined variable is returned from the function (in our case there is no value returned from the function, therefore stevie==&#8217;undefined&#8217;), however the new keyword causes the function to create a new instance of the Musician class an assign it to joe.</p>
<p>A class contains both fields and methods, both of which may be public or private. The this keyword creates a class level variable that is available to all instances of the class and is public to the class.  The var keyword creates a private which is only available inside the class, if someone trys to access a variable of this type from outside the class the variable will be returned as undefined.</p>
<p>So is that it then?  No, not quite.</p>
<p>The problem lies in the memory allocated as each new class is created.  Each time a class is created any methods which are part of the class are created in memory, this differs significantly from normal OO languages where a method is only ever created once in memory.  Allocating memory to a method for each instance of a class can be quite expensive in programming terms, but there is a way around this &#8211; prototypes.</p>
<h2>5. Prototypes &#8211; an object template</h2>
<p>Prototype is a  property on the base JavaScript object which is a child of all objects.  It is used to create properties and methods for all instances of an object.  It is used to create classes with public methods.  In the next example, I take the Musician object and redefine it using the prototype.</p>
<p><code><br />
function Musician(id, name, salary){<br />
//public<br />
this.Id=id;<br />
this.Name=name;<br />
this.Salary = salary;<br />
this.RehabDays = 0;<br />
}<br />
</code><code><br />
Musician.prototype.IsGoodEmployee = function(){<br />
if(this.RehabDays&lt;5){<br />
return true;<br />
}else{<br />
return false;<br />
}<br />
}<br />
</code><code><br />
Musician.prototype.InRehab=function(days){<br />
if(arguments[0]==null){<br />
this.RehabDays++;<br />
}else{<br />
this.RehabDays = this.RehabDays + days;<br />
}<br />
}<br />
</code><code><br />
Musician.prototype.CalculateBonus = function(){<br />
var bonusRate = 0.05;<br />
if(this.IsGoodEmployee()){<br />
bonusRate=bonusRate + 0.05;<br />
}<br />
return this.Salary * bonusRate;<br />
}<br />
</code><br />
I have updated the Musician class to add prototype methods to the class.  I have found that by adding the prototype methods, it is harder to keep variables private, the prototypes cannot access the private variables, so severely reduces the usability of private variables.  One way around this is to have a naming convention for &#8220;private&#8221; variables, e.g. this._name; were the underscore denotes that the variable is private and should not be used directly &#8211; not great I agree, but it’s the best there is at the minute.</p>
<p>Although at first it seems strange to define a class, then its methods  separately, I guess it is similar to creating and abstract class, then creating the concrete implementation.  In  a future blog I will show how to use the shorthand class notation to create a prototype class.</p>
<h2>6. Javascript has Object Inheritance and Polymorphism </h2>
<p>The final thing I didn’t know about Javascript (relating to object orientation) was that you could create a proper class model.  Javascript gives the ability to create class hierarchies and to have polymorphic methods.  In my last example in this blog, I have subclassed the Musician class and overridden the   CalculateBonus() function.  My thinking for this method was that a guitarist should get a bigger bonus because not only must a guitarist be a good musician, he/she must look cool too!!<br />
<code><br />
//1.  Create the base class - see the Musician example earlier<br />
</code><code><br />
//2. Create the sub class<br />
function Guitarist(id, name, salary,type){<br />
this.Type = type;  //lead or rhythm<br />
Musician.apply(this,arguments);<br />
}<br />
</code><code><br />
//3. Set the subclass prototype to use the base class methods<br />
Guitarist.prototype=new Musician();<br />
</code><code><br />
//4. Override any methods (or add methods)<br />
Guitarist.prototype.CalculateBonus = function(){<br />
var bonusRate = 0.1;<br />
if(this.IsGoodMusician()){<br />
bonusRate=bonusRate + 0.1;<br />
}<br />
return this.Salary * bonusRate;<br />
}<br />
Guitarist.prototype.Strum = function(){<br />
return "C Major";<br />
}<br />
</code><code><br />
//5. Ensure the constructor of the subclass is correct<br />
Guitarist.prototype.constructor = Guitarist;<br />
</code><br />
In the example I have sub-classed the Musician and created a Guitarist class.<br />
1.  The first step is to create the base class &#8211; you can see this in one of the earlier examples in this blog.</p>
<p>2.  Next I have created the constructor function.  This is created in a similar manner to the previous class except the last line of the constructor  calls the base classes constructor.  Note, I could have just as easily been more declarative when providing the argument collection, the example above is equilivant to  &#8220;Musician.apply(this,[id, name, salary]);&#8221; were I am specifying the arguments individually.  Also note, if there were no arguments to pass to the base constructor, I could have used the call method (Musician.call(this);).</p>
<p>3.  Then I set the prototype of my new class to the base class &#8211; when a method is executed, the Javascript runtime will check if the method exists on the current object, if not, the runtime will then check the objects prototype.  This provides a similar experience to class inheritance, even though the mechanics are somewhat different.</p>
<p>4.  The next step allows us to override methods and to create methods on our sub class.  In the example I have overridden the  CalculateBonus method, giving the Guitarist a bigger bonus, and added a new method, Strum();</p>
<p>5.  Finally we need to point our subtype&#8217;s prototype constructor to the correct type, (remember out subclass prototype is simply a clone of Musician, if we were to check the property Guitarist.prototype.constructor, we would be returned &#8220;Musician&#8221;).   So all we nee to do is set the constructor to the correct type (Guitarist in this example.)</p>
<p>Ok so that’s it &#8211; there we have it you can create object models in Javascript, just like you do in Java or C# or whatever &#8211; I know there are other OO languages out there, I couldn’t be bothered listing them ALL!  Finally in this article I will provide the test harness I used when writing this, just for completeness.  Note, I have used the Assert code from part one of this article to create my test method, and I have been lazy by putting my asserts into one test method, but you get the idea.<br />
<code><br />
function TestMusicians(){<br />
var zakk = new Musician(1,"Zakk Wylde","10000");<br />
Assert(zakk.CalculateBonus()==1000,"Bonus Should be 1000 (10%)");<br />
zakk.InRehab(4);<br />
Assert(zakk.CalculateBonus()==1000,"Bonus Should be 1000 (10%)");<br />
zakk.InRehab(); //add another sick day - 5 in total<br />
Assert(zakk.CalculateBonus()==500,"Bonus Should be 500 (5%)");<br />
var steve = new Guitarist(1,"Steve Vai","10000","Lead");<br />
Assert(steve.CalculateBonus()==2000,"Bonus Should be 2000 (20%)");<br />
steve.InRehab(10);<br />
Assert(steve.CalculateBonus()==1000,"Bonus Should be 1000 (10%)");<br />
alert("Test Passed");<br />
}</code></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=7&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/07/22/10-things-i-didn%e2%80%99t-know-about-javascript-part-2-object-orientation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>10 things I didn&#8217;t know about Javascript &#8211; Part 1 &#8211; Exception Management</title>
		<link>http://ajaxramble.wordpress.com/2008/07/09/10-things-i-didnt-know-about-javascript-part-1-exceptions/</link>
		<comments>http://ajaxramble.wordpress.com/2008/07/09/10-things-i-didnt-know-about-javascript-part-1-exceptions/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 21:05:44 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=5</guid>
		<description><![CDATA[Before delving into ajax, I decided to have a quick refresher into Javascript, I discovered quickly that there was more to Javascript than the simple language I learned years ago.  So I decided to go an learn then things about javascript which I did not know before.  There is nothing new on his list, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=5&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before delving into ajax, I decided to have a quick refresher into Javascript, I discovered quickly that there was more to Javascript than the simple language I learned years ago.  So I decided to go an learn then things about javascript which I did not know before.  There is nothing new on his list, but there may be a few things someone who has been a casual Javascript user (like me) might pick up before delving head-on into ajax.  Beware though, some of these items (for each loop and try/catch blocks) are only available in later versions of javascript.</p>
<p>Generally my 10 items have generally fallen into two categories, Exception (Error) Handling and Object Orientated Programming, with a few other bits and pieces thrown in for good measure&#8230;</p>
<p><span id="more-5"></span></p>
<h2>1.  You can catch Exceptions</h2>
<p>One of the first things that struck me when I started to look once more at javascript was the ability to catch exceptions in a similar manner to my favorite languages, C# and Java (Favorite because they are the only ones I ever learned!).  I have always thought that I was at the mercy of the browser when exceptions occured in my javascript.</p>
<p><code><br />
function HandleException(){<br />
try{<br />
var a=null;<br />
a.prop<br />
return 1/0;<br />
}<br />
catch(ex){<br />
alert(ex.name + ": " + ex.message);<br />
if(ex.stack!=null){<br />
alert(ex.stack);    //Firefox only<br />
alert(ex.description);    //IE only<br />
}<br />
}<br />
}<br />
</code><br />
In this code snippet an exception is thrown when trying to access a property on a null object.  Depending on your browser the exception object will have different properties, e.g. the stack property in firefox, or the description property in Internet Explorer.</p>
<h2>2. You can throw Exceptions</h2>
<p>Not only can you catch exceptions in Javascript, but you can also throw them.  Our javascript can now check parameters, properties, data, and respond to the caller in a manner similar we have been used to on the server.  Below is an example of creating our own Exception.  I have created a simple method to act as a code assertion in a similar manner to xUnit or debug statement, and called it from the second method.<br />
<code><br />
function Assert(isTrue, message){<br />
if(!isTrue)<br />
{<br />
var err = new Error();<br />
err.message = message;<br />
err.name = "AssertionException";<br />
throw err;<br />
}<br />
}</code><br />
<code><br />
function TestAssert(){<br />
try{<br />
Assert(1==1,"This message should not be displayed");<br />
Assert(1==2,"This message should be displayed");<br />
}catch(ex)<br />
{<br />
alert(ex.message);<br />
}<br />
}<br />
</code></p>
<p>The first method simply creates a new error object which will be thrown is the isTrue argument is false.  The second method uses the try/catch construct to display an error message if an exception is thrown.</p>
<h2>3. You can manage exceptions in one place</h2>
<p>The third thing I didn&#8217;t know was you can catch all exceptions in one place.  I always thought you were at the mercy of your browser.  Javascript provides a mechanism of handling unhandled exceptions in a similar manner to using the Global.asax in Asp.Net applications to catch exception not delt with lower in the stack.  The code below shows how to write an exception handler and attach it to the window object.<br />
<code><br />
function errorHandler (message, url, lineNumber) {<br />
var outputMessage =<br />
"Message: " + message +<br />
"\nURL: " + url +<br />
" (ln: " + lineNumber + ")";<br />
alert (outputMessage);<br />
}</code><br />
<code><br />
//Attach to window<br />
window.onerror = errorHandler;<br />
</code><br />
The event handler takes three arguments, the error message, the url and the linenumber.  The example above simply rolls a error message and presents it to the user in an alert.  However this method could be used to  ignore errors, display an error message on screen, redirect the user, or even log the error to the server via an Ajax call.</p>
<p>In part two of this post I will discuss the next three things i didn&#8217;t know about Javascript, creating objects, prototypes and object inheritance</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=5&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/07/09/10-things-i-didnt-know-about-javascript-part-1-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
		<item>
		<title>Lost My Cherry</title>
		<link>http://ajaxramble.wordpress.com/2008/07/02/lost-my-cherry/</link>
		<comments>http://ajaxramble.wordpress.com/2008/07/02/lost-my-cherry/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 21:59:37 +0000</pubDate>
		<dc:creator>ajaxramble</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ajaxramble.wordpress.com/?p=3</guid>
		<description><![CDATA[This is me loosing my Blog Cherry,  I have decided to write a blog simply to give me an excuse to learn new technology and get better at expressing what I know in writing.  Some of what I write will be notes, at other times there will be examples, and sometimes I amy just write [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=3&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is me loosing my Blog Cherry,  I have decided to write a blog simply to give me an excuse to learn new technology and get better at expressing what I know in writing.  Some of what I write will be notes, at other times there will be examples, and sometimes I amy just write random &#8220;stuff&#8221; &#8211; thats why I have called this blog a ramble.</p>
<p>Even though this blog is titled &#8220;Ajax Ramble&#8221; I will try to cover a number of technologies (probably mostly UI, and generally Microsoft).  I enjoy technology and want to share my experiences in learning new things, if nothing more, it will be a notebook of learnings and ideas.</p>
<p>Just as I write this I see the autosave function of wordpress and think &#8220;Thats cool!&#8221;.</p>
<p>Within the next few days I hope to upload my first proper blog, &#8220;10 things I didn&#8217;t know about about Javascript&#8221;.</p>
<p>(I told you this was a ramble)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/ajaxramble.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/ajaxramble.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajaxramble.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajaxramble.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajaxramble.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajaxramble.wordpress.com&amp;blog=4127578&amp;post=3&amp;subd=ajaxramble&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ajaxramble.wordpress.com/2008/07/02/lost-my-cherry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b5750a993e3930633bb1d57389d5957?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajaxramble</media:title>
		</media:content>
	</item>
	</channel>
</rss>
