<?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>James Cryer&#039;s Blog</title>
	<atom:link href="http://jamescryer.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jamescryer.wordpress.com</link>
	<description>Alt indie + JavaScript.</description>
	<lastBuildDate>Sun, 04 Dec 2011 05:44:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jamescryer.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>James Cryer&#039;s Blog</title>
		<link>http://jamescryer.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jamescryer.wordpress.com/osd.xml" title="James Cryer&#039;s Blog" />
	<atom:link rel='hub' href='http://jamescryer.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SASS: Learning to let go of your CSS sensibilities</title>
		<link>http://jamescryer.wordpress.com/2011/12/04/sass/</link>
		<comments>http://jamescryer.wordpress.com/2011/12/04/sass/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 05:38:16 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[SASS]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=439</guid>
		<description><![CDATA[SASS to my surprise is really nice way to build large style sheets. It&#8217;s programming-centric approach (as opposed to markup-centric) allows more explicit inheritance patterns making module styles easier to read and easier to maintain. But there is a catch.. My main problem with CSS is that it&#8217;s a markup language with added inheritance. &#8220;DAMN [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=439&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://sass-lang.com/" target="_blank">SASS</a> to my surprise is really nice way to build large style sheets. It&#8217;s programming-centric approach (as opposed to markup-centric) allows more explicit inheritance patterns making module styles easier to read and easier to maintain. But there is a catch..</p>
<p><span id="more-439"></span></p>
<p>My main problem with CSS is that it&#8217;s a markup language with added inheritance. &#8220;DAMN YOU CASCADE!!&#8221;, I&#8217;ve screamed this so many times at work. I spend far too much time fighting legacy code, the cost of re-factoring would be significant so I add another !important or add an ID to the selector. Constantly overriding is a <a title="Call Super anti-pattern" href="http://en.wikipedia.org/wiki/Call_super" target="_blank">bad smell</a>. CSS doesn&#8217;t scale without being explicit.</p>
<p>There is a big mental shift when moving from CSS to SASS. Thinking of things as modules helps.</p>
<p><pre class="brush: plain;">
.clickable {
  color: blue;
  &amp;:hover {
    color: red;
    }
  .ie &amp; {
    padding-left: 1px; //some pretend box-model hack for IE
    }
  }
</pre></p>
<p>The above example uses the SCSS style. Note the use of the ampersand character to denote &#8216;this&#8217;.  SASS allows us to encapsulate state and behaviours within a module in pretty much the same logical way that I would approach a JavaScript module.</p>
<p>Reuse can be achieved with variables, and inheritance patterns using @extend or @include.</p>
<p><pre class="brush: plain;">
$column-width: 256px;

@mixin astract {
  white-space: nowrap;
  overflow: hidden;
  width: $column-width;
  }

.clickable {
  @include abstract;
  color: blue;
  &amp;:hover {
    color: red;
    }
  .ie &amp; {
    padding-left: 1px; //some pretend box-model hack for IE
    }
  }

.special-clickable {
  @extend .clickable;
  border: 1px solid: blue;
  }
</pre></p>
<p>I love that we can achieve <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank">DRY</a> code in this way.  Sure you can extend style modules in CSS, but the relationships are defined explicitly in the HTML not in the stylesheet.  This is a massive discoverability problem. SASS allows us to define these relationships in one place.</p>
<p>This is one way of achieving the same thing in CSS. Note that I&#8217;m also providing a HTML example.</p>
<p><pre class="brush: plain;">
.clickable {
  white-space: nowrap;
  overflow: hidden;
  width: 256px;
  color: blue;
  }
  .clickable:hover {
    color: red;
    }
  .ie .clickable {
    padding-left: 1px; //some pretend box-model hack for IE
    }

.special-clickable {
  border: 1px solid: blue;
  }
</pre><pre class="brush: plain;">
&lt;button class=&quot;clickable special-clickable&quot;&gt;click me&lt;/button&gt;
</pre></p>
<p>As I mentioned earlier, there is a downside to using SASS, <strong>it compiles to CSS</strong>. It produces CSS without the same level of code re-use that you might strive to achieve yourself.  SASS is lazy, especially where mixins are used. Generated CSS becomes bloated quickly, load time of the web page increases.</p>
<p>As with so much in our Industry, it&#8217;s a trade off.  SASS is genuinely a more managable and enjoyable way to style the UI.  But as a tool for building CSS? It&#8217;s as good as it can be, which isn&#8217;t quite good enough.  The CSS bloat issue only begins to appear on larger UI&#8217;s, is that ok? I guess that depends on how bandwidth sensitive your users are.  And selector performance?  I haven&#8217;t noticed any problems though stylistically I would say that SASS encourages deep nesting of selectors which <a href="http://blog.archive.jpsykes.com/152/testing-css-performance-pt-2/" target="_blank">may be an issue</a>. </p>
<p>In this day and age modern web browsers and network infrastructures can easily absorb the extra weight. CSS file sizes generated from SASS are in no way comparable to the files sizes you might expect from many JS libraries.  And CSS selector performance is barely worth monitoring to be honest (Unless your users use IE6).</p>
<p>I&#8217;d recommend you have a play with SASS if you haven&#8217;t already, but you&#8217;re going to have to let go of some of your CSS sensibilities before you begin to enjoy it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/439/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/439/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/439/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=439&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/12/04/sass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript Scope: Closure</title>
		<link>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-closure/</link>
		<comments>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-closure/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 13:29:08 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=402</guid>
		<description><![CDATA[Closures provide a way to hold or trap an activation object in memory. They can be used for defining private variables, and storing variables outside of a functions life-cycle. JavaScript has function-level scope only, so unlike other C languages a &#8216;for&#8217; or &#8216;if&#8217; block won&#8217;t hold scope. To create scope within the if block we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=402&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Closures provide a way to hold or trap an <a href="http://jamescryer.wordpress.com/2011/07/10/javascript-scope-execution-context/" title="JavaScript Scope: Execution Context">activation object</a> in memory.</p>
<p>They can be used for defining private variables, and storing variables outside of a functions life-cycle.</p>
<p><span id="more-402"></span></p>
<p>JavaScript has function-level scope only, so unlike other C languages a &#8216;for&#8217; or &#8216;if&#8217; block won&#8217;t hold scope.</p>
<p><pre class="brush: plain;">
for (var homer in ['doh!','ray','mee']) {
// do something with homer
}

console.log(homer); // logs 'mee'
</pre><br />
<pre class="brush: plain;">
var homer = 'hmmmm donuts';
if(true){
var homer = 'doh!';
// other code
}
console.log(homer); // logs 'doh!'
</pre></p>
<p>To create scope within the if block we could do the following:</p>
<p><pre class="brush: plain;">
var homer = 'hmmmm donuts';
if(true){
(function(){
var homer = 'doh!';
// other code
}());
}
console.log(homer); // 'hmmmm donuts'
</pre></p>
<p>But generally it&#8217;s not good practice to reuse variable names for different purposes.</p>
<p>In the global scope, variables resolve to the global object &#8216;window&#8217;. &#8216;this&#8217; in a global function will be the global object, but variables defined within that function wont resolve to the global object. Functions have there own activation object.</p>
<p><pre class="brush: plain;">
function(){
var homer = 'woo hoo';

var myobject = {
homer: 'spiderpig, spiderpig...',
say: function(){
console.log(homer);
console.log(this.homer);
}
}
myobject.say();
}
</pre></p>
<p>From this example we first log &#8216;woo hoo&#8217; from current function scope then &#8216;spiderpig, spiderpig&#8230;&#8217; as defined on the object.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/402/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/402/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/402/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=402&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-closure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript Scope: What is this?</title>
		<link>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-what-is-this/</link>
		<comments>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-what-is-this/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 13:15:21 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=400</guid>
		<description><![CDATA[&#8216;this&#8217; will always resolve to the global object unless: The containing function is instantiated with the ‘new’ keyword Or.. The function is called on an owner object. Take this example, what do you think will be logged? Answer: &#8216;foobar&#8217; gets logged. &#8216;this&#8217; gets defined when the activation object is created for the current execution. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=400&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8216;this&#8217; will always resolve to the global object unless:</p>
<p><strong>The containing function is instantiated with the ‘new’ keyword</strong></p>
<p><pre class="brush: plain;">
var me = this;
function Test(){
	console.log(this === me);
}
var myTest = new Test();  // false
</pre></p>
<p>Or.. <strong>The function is called on an owner object.</strong></p>
<p><pre class="brush: plain;">
var obj = {
myFunc: function(){
return this;
}
};
console.log( this === obj.myFunc() ); // false
</pre></p>
<p><span id="more-400"></span></p>
<p>Take this example, what do you think will be logged?</p>
<p><pre class="brush: plain;">
var i = {
myvar: 'something',
invoke: function(callback){
callback();
}
};

var obj1 = {
myvar: 'default',
counter: function(){
if(!this.myvar){
this.myvar = 'foobar';
}
console.log(this.myvar);
}
}

i.invoke(obj1.counter);
</pre></p>
<p>Answer: &#8216;foobar&#8217; gets logged.</p>
<p>&#8216;this&#8217; gets defined when the <a href="http://jamescryer.wordpress.com/2011/07/10/javascript-scope-execution-context/" title="JavaScript Scope: Execution Context" target="_blank">activation object</a> is created for the current execution. The function reference is executed without an owner object so this will resolve to the global object;</p>
<p>What&#8217;s worse about this is that window now has a new property called myvar.</p>
<p>To complicate matters further you can explicitly define &#8216;this&#8217;. Either by (re)assigning the method to the desired owner method or by using the call and apply methods.</p>
<p><pre class="brush: plain;">
i.counter = obj.counter;
i.counter() // 'something'

obj1.counter.call(i); // 'something'
obj1.counter.apply(i, []); // 'something'
</pre></p>
<p>They are basically the same method except that apply() will let you pass in the arguments object (or an array of arguments).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/400/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/400/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/400/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=400&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-what-is-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript Scope: Execution Context</title>
		<link>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-execution-context/</link>
		<comments>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-execution-context/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 13:11:23 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=398</guid>
		<description><![CDATA[The Execution Context is an abstract representation of the current runtime environment in JavaScript. To explain a little better, the Execution Context is formed of three components. Lexical Environment Variable Environment This binding Perhaps a better way to think of this is: Scope chain Local variables &#8216;this&#8217; keyword The scope chain represents an array of parent [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=398&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf" target="_blank">The Execution Context</a> is an abstract representation of the current runtime environment in JavaScript. To explain a little better, the Execution Context is formed of three components.</p>
<ul>
<li>Lexical Environment</li>
<li>Variable Environment</li>
<li>This binding</li>
</ul>
<p><span id="more-398"></span></p>
<div>Perhaps a better way to think of this is:</div>
<div>
<ul>
<li>Scope chain</li>
<li>Local variables</li>
<li>&#8216;this&#8217; keyword</li>
</ul>
</div>
<p>The scope chain represents an array of parent &#8216;Variable environments&#8217; up to and including the global variable environment.</p>
<p>Each Variable environment is in fact an object called an activation (or variable) object. Though not a real object in the normal sense, it does have properties which can be accessed.</p>
<p><pre class="brush: plain;">
{
__parent__ :[Object reference],
arguments: [Lots of fun that I wont go into now]
this: [Object reference]
mylocalVar: [undefined]
}
</pre></p>
<p>The above example represents the activation object after the initialisation of the current context, the myLocalVar property is a local variable.  At this point the activation object is sometimes referred to as the Variable object, as far as I understand they are essentially the same thing (if for the moment we pretend the with() method doesn&#8217;t exist).</p>
<p>The &#8216;this&#8217; property  refers to the owner object (by default this is the global object .i.e. window).</p>
<p>The __parent__ property is a reference to the parent activation object. This object is not explicitly accessible, though access to properties on this object are implied from the scope chain.</p>
<p>The global context is some what confused, &#8216;this&#8217; resolves to the activation object itself thus&#8230;</p>
<p><pre class="brush: plain;">

var foo = 'bar'
console.log(window.foo); // bar
console.log(this.foo); // bar

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/398/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/398/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/398/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=398&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/07/10/javascript-scope-execution-context/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>Free no.de domain for node.js server</title>
		<link>http://jamescryer.wordpress.com/2011/04/30/no-de-domain/</link>
		<comments>http://jamescryer.wordpress.com/2011/04/30/no-de-domain/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 17:32:53 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=381</guid>
		<description><![CDATA[At the time of writing this, Joyent are literally giving away free &#8216;smartmachines&#8217;  for running  nodejs servers with no.de domains. Awesome, I got one by going to their site, creating an account, and then running the curl command they gave me to request a coupon.  I think they make you do the last step to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=381&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>At the time of writing this, <a href="http://no.de">Joyent</a> are literally giving away free &#8216;smartmachines&#8217;  for running  nodejs servers with no.de domains.</p>
<p>Awesome, I got one by going to their site, creating an account, and then running the curl command they gave me to request a coupon.  I think they make you do the last step to make sure you are actually a geek&#8230;  A week later I got an email explaining how to use their API to get the coupon.  I logged in, and provisioned the machine.</p>
<p>Deployment is easy with git, and they provide a good <a href="http://wiki.joyent.com/display/node/Getting+Started+with+a+Node+SmartMachine">Get started guide</a>.  I had some problems because the version of Node I had locally was older than the one installed by default on the Joyent sever.  You can define which version you want to use with a config file, though best stick to the latest version to avoid versioning issues with other node modules like Express.js.  They have npm installed as well so it is really easy to install he modules you want.</p>
<p>#WIN</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/381/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/381/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/381/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=381&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/04/30/no-de-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>JavaScript BDD with Jasmine and JsTestDriver</title>
		<link>http://jamescryer.wordpress.com/2011/03/22/javascript-bdd-with-jasmine-and-jstestdriver/</link>
		<comments>http://jamescryer.wordpress.com/2011/03/22/javascript-bdd-with-jasmine-and-jstestdriver/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 15:46:03 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[jstd]]></category>
		<category><![CDATA[jstestdriver]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=372</guid>
		<description><![CDATA[You may have heard about Jasmine, it’s a JS framework for supporting BDD.  It has become very popular so for the last couple of months I have been playing with it to see if it could work for us. The big hurdle for integration at my company was that we are already tied to another [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=372&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You may have heard about <a href="http://pivotal.github.com/jasmine/" target="_blank">Jasmine</a>, it’s a JS framework for supporting BDD.  It has become very popular so for the last couple of months I have been playing with it  to see if it could work for us.</p>
<p>The big hurdle for integration at my company was that we are already tied to another JS test framework, <a href="http://code.google.com/p/js-test-driver/" target="_blank">JsTestDriver</a> or JSTD for short.</p>
<p><span id="more-372"></span></p>
<p>JSTD is awesome.  It&#8217;s a &#8216;remote javascript console&#8217; which allows the execution of JS tests via the command line.  Unlike similar products such as <a href="https://github.com/relevance/blue-ridge" target="_blank">Blue Ridge</a> JSTD does not provide headless testing.  Tests get pushed using the command line to a server, the server can run either locally or somewhere on the accessible network. Slave browsers have to be set up to listen to the server.  When the server gets invoked the test are executed simultaneously on each browser, the results are fed back to the command line.</p>
<p>The nice thing about JSTD is that it fits well with continuous integration systems.  There are a few ways you could set this up.  My preference is to have a server permanently running with Internet Explorer, Firefox and Chrome as slaves (best keep them on a unused PC or VM).  Tell Team City to watch for code changes and trigger test execution via the command line.  JSTD will create JUnit reports, Team city can watch this directory and show failed tests in its UI.</p>
<p>There is a Jasmine adapter for JSTD, by including Jasmine and the adapter in  the JSTD config we can write Jasmine style tests while keeping the benefits of  JSTD (like Team city integration, JUnit reporting, remote hosting).  Moving to  Jasmine does not create conflicts with existing tests, they carry on working as  before.</p>
<p>So what do the tests look like, and why might it be better than your current  setup?</p>
<p>Jasmine provides a much more language-centric approach to writing tests, for  me it’s far more readable.  It’s designed to support BDD, its syntax encourages  clear separation of context and specification.</p>
<p><pre class="brush: plain;">
describe(&quot;myJsComponent&quot;, function(){

  describe(&quot;when the sky is blue&quot;, function(){

    beforeEach(function(){
      // set up context
      // initialise JS component
    });

    afterEach(function(){
      // clear up context, unbind events, destroy DOM
    });

    it('should shout something to make you go outside ', function(){
      expect(  myJsComponent.shout()  ).toBe( &quot;why are you inside?&quot; );
    });

    it('should not say something to make you stay inside ', function(){
      expect(  myJsComponent.say()  ).not.toBe( &quot;stay here, grab a coffee&quot; );
    });

  });
});
</pre></p>
<div id="1d06aee0-f033-40de-9387-d02fce094482">
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas,"Courier New",courier,monospace; background-color: rgb(255, 255, 255); }.csharpcode pre { margin: 0em; }.csharpcode .rem { color: rgb(0, 128, 0); }.csharpcode .kwrd { color: rgb(0, 0, 255); }.csharpcode .str { color: rgb(0, 96, 128); }.csharpcode .op { color: rgb(0, 0, 192); }.csharpcode .preproc { color: rgb(204, 102, 51); }.csharpcode .asp { background-color: rgb(255, 255, 0); }.csharpcode .html { color: rgb(128, 0, 0); }.csharpcode .attr { color: rgb(255, 0, 0); }.csharpcode .alt { background-color: rgb(244, 244, 244); width: 100%; margin: 0em; }.csharpcode .lnum { color: rgb(96, 96, 96); } -->Jasmine provides a broad range of test methods (known as matchers.  e.g.  toBe() ) and uses deferred objects to enable negative assertions to be made in a  fluent syntax (e.g. .not.toBe() ).  We can specify custom matchers to make the  specification clearer or two encapsulate reusable test logic.</p>
<p>Outputted errors look  a bit like this from command:</p>
<p><span style="font-family:Courier New;">jquery.editable when field is uneditable .should  become editable on click failed (15.00 ms): Error: Expected &#8216;editable&#8217; to equal  &#8216;I made it fail&#8217;.<br />
Error: Expected &#8216;editable&#8217; to equal &#8216;I made it  fail&#8217;.</span></p>
<p>You can find out more about Jasmine, Jasmine adapter and JSTD from the  following links.</p>
<ul>
<li><a href="http://pivotal.github.com/jasmine/">Jasmine</a></li>
<li><a href="https://github.com/velesin/jasmine-jquery" target="_blank">jQuery extentions for Jasmine</a></li>
<li><a href="https://github.com/mhevery/jasmine-jstd-adapter">Jasmine  adapter</a></li>
<li><a href="http://code.google.com/p/js-test-driver/">JSTD</a></li>
</ul>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/372/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=372&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2011/03/22/javascript-bdd-with-jasmine-and-jstestdriver/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>Keep it simple</title>
		<link>http://jamescryer.wordpress.com/2010/12/04/keep-it-simple/</link>
		<comments>http://jamescryer.wordpress.com/2010/12/04/keep-it-simple/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 14:59:43 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[Philosophy]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=342</guid>
		<description><![CDATA[It is very easy to overcomplicate things, whether in life or work it is always best to stand back and take some time to think about the problem, understand what needs to be solved.  Now you could methodically go through through every possible solution, weigh up the pros and cons and then decide what to do, that&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=342&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is very easy to overcomplicate things, whether in life or work it is always best to stand back and take some time to think about the problem, understand what needs to be solved.  Now you could methodically go through through every possible solution, weigh up the pros and cons and then decide what to do, that&#8217;s fine, that works.  But I think it is easy to miss things, an edge case or a related problem.</p>
<p>The best thing to do is literally walk away from it, if you have the luxury of time then use that time to talk to others, research.  Or even better, pick up a guitar, draw a pretty picture; do something else.</p>
<p><span id="more-342"></span></p>
<p>I read recently that the sub conscious is more active than you might think.  It is almost completely responsibly for problem solving.  Sounds strange but how many times have you got stuck with something then after an hour perhaps a day figured it out, even if you&#8217;ve spent the time doing something completely different.</p>
<p>Here is a good talk on <a href="http://clojure.blip.tv/file/4457042/" target="_blank">Hammock Driven Development</a> which reiterates that giving time to solving a problem works.</p>
<p>Once you understand a problem then it is best to strongly define that solution, try to imagine it, write it down or draw it if possible, talk to others about it. The solution should be terse and simple. It should not define a product or feature, it should explain how <strong>Given </strong>X is true, <strong>When </strong>Y is doing that <strong>Then </strong>Z should do this.</p>
<p>I use the Given, When, Then terminology at work to define the goal of the solution in development. Our QA team also use it to define test plans to affirm that the solution does indeed enable the intended goal.</p>
<p>In the UX domain there is this concept of Goal Driven Design.</p>
<p>&#8220;<strong>Given </strong>user A is a new user <strong>When </strong>user A first hits the web app <strong>Then </strong>user A should be encouraged to invite other people.&#8221;</p>
<p>The above goal defines a business objective to increase virality, and represents a small chunk of a user story.  There could be many solutions to this, a bright pink invite button which leads to an invite form, perhaps the first screen they hit asks them to connect with facebook and/or gmail. Whatever the solution is, it should achieve the set goal as simply as possible, if this is the main goal then this should become the primary part of the design, everything else should become secondary or better, non-existent.</p>
<p>Break problems into smaller chunks and define end goals to develop better, simpler solutions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/342/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=342&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2010/12/04/keep-it-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>Node.js fun</title>
		<link>http://jamescryer.wordpress.com/2010/11/14/node-js-fun/</link>
		<comments>http://jamescryer.wordpress.com/2010/11/14/node-js-fun/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 21:17:08 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[v8]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=334</guid>
		<description><![CDATA[I&#8217;ve started to play around with node.js (the SSJS framework built on V8). I had a bit of trouble installing it on my old version of Ubuntu so opted to install it on Cygwin. If you are planning to do the same I&#8217;d recommend you read Getting Started with Node.js on Windows and Node.js on Windows [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=334&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to play around with <a href="http://nodejs.org/" target="_blank">node.js</a> (the SSJS framework built on <a href="http://en.wikipedia.org/wiki/V8_(JavaScript_engine)" target="_blank">V8</a>).  I had a bit of trouble installing it on my old version of Ubuntu so opted to install it on Cygwin.  If you are planning to do the same I&#8217;d recommend you read <a href="http://codebetter.com/blogs/matthew.podwysocki/archive/2010/09/07/getting-started-with-node-js-on-windows.aspx" target="_blank">Getting Started with Node.js on Windows</a> and <a href="http://blog.brev.name/2010/09/nodejs-on-windows-7-under-cygwin.html" target="_blank">Node.js on Windows 7 under Cygwin, &#8220;FixImage error 13&#8243; problem</a>.</p>
<p>I very quickly built a hello world app, it was really easy.  Great I thought, what next &#8230; A real time chat app?</p>
<p>A few hours later I&#8217;d built just that, albeit mostly using the <a href="http://socket.io/" target="_blank">Socket.IO</a> chat example. Socket.IO is ridiculously powerful, it enables push messaging from the server to the client and apparently scales really well.</p>
<p>So then I wanted to build multiple pages, multiple chatrooms. Enter <a href="http://expressjs.com/" target="_blank">Express.js</a>. Express.js makes URI routing, session handling and view rendering so much easier. It&#8217;s easy to use as well.</p>
<p>Next.. Chat rooms are boring, lets add some HTML5 in the form of Canvas.  Taking a simple jQuery canvas plugin called <a href="http://www.rich-rogers.com/archive/jquery-plugin-scratchpad" target="_blank">Scratch Pad</a> and hooking it up to Socket.IO I was able to push custom events like &#8216;startDraw&#8217; down to the server whereupon the server broadcasts that event to all the listening clients, the client then updates the canvas.</p>
<p>By the following weekend I had built a real time chat application (and I mean real time) which also enables collaborative drawing.</p>
<p>I&#8217;m am really loving Node.js at the moment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/334/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/334/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/334/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=334&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2010/11/14/node-js-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a rich internet application that works in IE6</title>
		<link>http://jamescryer.wordpress.com/2010/10/24/riaie6/</link>
		<comments>http://jamescryer.wordpress.com/2010/10/24/riaie6/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 16:09:35 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=304</guid>
		<description><![CDATA[So what do you do when your boss says &#8220;let&#8217;s build us a shiny Ajax web thingy that will work on the IE6 browser that our high paying customers use.&#8221; ? Well I said &#8220;Sure thing!&#8221;. A JavaScript toolkit like jQuery will go a long way in helping you with this, normalising all of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=304&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So what do you do when your boss says &#8220;let&#8217;s build us a shiny Ajax web thingy that will work on the IE6 browser that our high paying customers use.&#8221; ? Well I said &#8220;Sure thing!&#8221;.</p>
<p>A JavaScript toolkit like jQuery will go a long way in helping you with this, normalising all of the events and hiding the hacks.  Let an existing toolkit do the hard work.</p>
<p>With regard to CSS layouts, you could trying using an existing grid framework like <a href="http://960.gs/">960</a> or <a href="http://www.blueprintcss.org/">Blueprint</a> (tbh I don&#8217;t think they are that reliable). Alternatively, use a HTML 4 doctype to avoid <a href="http://www.quirksmode.org/css/quirksmode.html">quirks mode</a> and remember <a href="http://msdn.microsoft.com/en-us/library/bb250481(VS.85).aspx">hasLayout</a>.</p>
<p>IE6 is terrible at DOM traversal and manipulation; minimise the size of the DOM and always use IDs to get what you want, or at least use an ID to add context to your traversal. Unfortunately jQuery methods like live and delegate use DOM traversal to work out if a callback should be fired or not, there are some good notes on this by <a href="http://paulirish.com/2010/on-jquery-live/">Paul Irish</a> and on the <a href="http://forum.jquery.com/topic/jquery-live-jquery-fn-live-discussion">jQuery discussion board</a>.  <a href="http://jamescryer.wordpress.com/2010/10/24/delegation/">DIY event delegation</a> wins here and is quite easy to do. More often than not you can limit DOM walks and still provide the same functionality, with regard to event callbacks bound to form inputs you don&#8217;t need to do any DOM walking at all because you can&#8217;t have a child element of an INPUT or TEXTAREA.</p>
<p>If that&#8217;s not enough then you can investigate any problems with the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=95e06cbe-4940-4218-b75d-b8856fced535">IE Developer Toolbar</a> or <a href="http://ajax.dynatrace.com">dynaTrace Ajax</a>, the latter being the best thing since the invention of firebug.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/304/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=304&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2010/10/24/riaie6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
		<item>
		<title>DIY event delegation with jQuery</title>
		<link>http://jamescryer.wordpress.com/2010/10/24/delegation/</link>
		<comments>http://jamescryer.wordpress.com/2010/10/24/delegation/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 15:55:11 +0000</pubDate>
		<dc:creator>jamescryer</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Advanced JavaScript]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://jamescryer.wordpress.com/?p=311</guid>
		<description><![CDATA[I noticed on a recent project that jQuery&#8217;s event delegation methods used jQuery.closest, a method that walks up the DOM to find the closest element of a given type/selector. As useful as it is, IE6 &#38; 7 suck at DOM traversal, and even modern browsers slowly grind to a halt when dealing with massive DOMs. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=311&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I noticed on a recent project that jQuery&#8217;s event delegation methods used jQuery.closest, a method that walks up the DOM to find the closest element of a given type/selector.  As useful as it is, IE6 &amp; 7 suck at DOM traversal, and even modern browsers slowly grind to a halt when dealing with massive DOMs.  If this is a concern then it&#8217;s better to do it yourself.</p>
<p><span id="more-311"></span></p>
<p>Below is a simple example of some HTML which has a link (with a child SPAN) and an INPUT &#8211; imagine they are deep in the DOM, perhaps in a nested table.  If I use live or delegate to bind events to these elements, then I invoke that event within the context area, jQuery will walk the DOM from the element the event bubbled from to the context element; this could be a traversal of ten or more elements.  Now imagine you have twenty or more event bindings.  The cost of using live or delegate quickly becomes apparent, especially in IE6.</p>
<p><pre class="brush: xml;">
&lt;a href=&quot;#&quot; class=&quot;specific-link&quot;&gt;&lt;span&gt;My link&lt;/span&gt;&lt;/a&gt;
&lt;form action=&quot;//myResponsePage&quot;&gt;
    &lt;input type=&quot;text&quot; /&gt;
    &lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;
</pre></p>
<p>Below is an example of how you can use regular event binding to create your own optimised delegation method.  This example is defined as a jQuery plugin.  For elements that can not have child elements there is no DOM traversal, for other elements we only ever take three steps up the DOM.  The number of steps will depend on your application but I can&#8217;t imagine you&#8217;d ever want more than five steps.</p>
<p><pre class="brush: jscript;">
(function QuickDelegateClosure($){

	var hasNoChildrenRegEx = / input| texarea| select| img/;

	$.fn.quickDelegate = function(selector, event, callback){
		return this.bind(event, _matchSelectorAndInvokeCallback );
		
		function _matchSelectorAndInvokeCallback(event){
			var target, steps = hasNoChildrenRegEx.test(' '+selector)
					  ? 0
					  : 3;
					  
			target = _getClosestWithinNumberOfSteps(event.target,selector,steps);
			if( target ){
				return callback.apply(target,[event]);
			}
		}
	};

	function _getClosestWithinNumberOfSteps(target, selector, steps){
		var count = 0;
		do {
			if ($(target).is(selector)) return target;
		}
		while( (target = target.parentNode) &amp;&amp; count++ &lt; steps );
	}
})(jQuery);
</pre></p>
<p>And below shows how we might invoke this plugin.</p>
<p><pre class="brush: jscript;">
$(function(){
	$('body')
		.quickDelegate('.specific-link', 'click', doSomething )
		.quickDelegate('input[type=text]', 'keypress', doSomething );

	function doSomething(){/*Your code*/}
});
</pre></p>
<p>I wrote this pretty quickly, the regular expression it uses to determine if the selector is for an element that has no children is pretty crude.  I haven&#8217;t formally tested the performance gain of using this compared to using jQuery.delegate though I&#8217;ve been impressed with the performance of click and keypress events in IE6 using the same technique.  The performance in the application I was working on was notably increased.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamescryer.wordpress.com/311/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamescryer.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamescryer.wordpress.com/311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jamescryer.wordpress.com&amp;blog=6821554&amp;post=311&amp;subd=jamescryer&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jamescryer.wordpress.com/2010/10/24/delegation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/713f28722c6c5988c5bae2e44eda20b2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamescryer</media:title>
		</media:content>
	</item>
	</channel>
</rss>
