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

<channel>
	<title>PHP, Web and IT stuff &#187; javascript</title>
	<atom:link href="http://www.webdigi.co.uk/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdigi.co.uk/blog</link>
	<description>Little words of wisdom</description>
	<lastBuildDate>Sat, 04 Sep 2010 22:35:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rise of Javascript</title>
		<link>http://www.webdigi.co.uk/blog/2009/rise-of-javascript/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/rise-of-javascript/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 16:00:54 +0000</pubDate>
		<dc:creator>iphp</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=440</guid>
		<description><![CDATA[Since its birth in 1994, Javascript has come a long way. Today it is one of the most popular programming languages on the web. Javascript has been on the rise and is growing faster since AJAX based applications reignited professional developer interest. It is now possible to it to write applications on the server, the [...]]]></description>
			<content:encoded><![CDATA[<p>Since its birth in 1994, Javascript has come a long way. Today it is one of the most popular programming languages on the web. Javascript has been on the rise and is growing faster since AJAX based applications reignited professional developer interest. It is now possible to it to write applications on the server, the mobile devices, on the browsers (add ons and plugins),  inside PDF documents, even in some remote controls and many more to come.</p>
<p><strong>Javascript application development in Mobile devices </strong></p>
<div id="attachment_470" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-470" title="palm_webos_450" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/06/palm_webos_450-300x216.jpg" alt="Build Native Applications using Javascript" width="300" height="216" /><p class="wp-caption-text">Build Native Applications using Javascript</p></div>
<p>Palm&#8217;s new OS is the first mobile platform to be built from the ground up to combine standard technology, innovation and integration. At its core, webOS leverages several industry-standard technologies, including web technologies such as CSS, XHTML and JavaScript. You can think of webOS applications as native applications, but built from the same standard HTML, CSS and JavaScript that you&#8217;d use to develop web applications. Palm has extended the standard web development environment through a JavaScript framework that gives standardized UI widgets, and access to selected device hardware and services.</p>
<p>Javascript can be used on the <strong>iphone</strong> too.  The HTML 5 specification provides a new mechanism for client-side data storage: JavaScript database support. This feature shipped originally with iPhone OS 2.1. When you use “Add to Home Screen” from the “+” button on Safari for iPhone, a web application with a manifest defined (per the HTML5 spec) will be saved with any cached resources.  It is also worth noting that these features have not been added to Safari on Mac OS X or Windows.</p>
<p><strong>Desktop Application development using Javascript</strong></p>
<p>Adobe AIR is a cross-platform desktop runtime created by Adobe that allows web developers to use web technologies to build and deploy Rich Internet Applications (RIAs) and web applications to the desktop. This means what you can write you application using Javascript and then let AIR to figure out how to run your code in Windows, Linux, Mac and future operating systems.</p>
<div id="attachment_453" class="wp-caption alignleft" style="width: 360px"><img class="size-medium wp-image-453 " title="airtotal2" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/06/airtotal2-300x200.png" alt="airtotal2" width="350" height="233" /><p class="wp-caption-text">Desktop App using Javascript</p></div>
<p>The application shown in the pic is written using Javascript, HTML and CSS. It uses the ExtJS library. Javascript can be used to dock the application in the taskbar, delete and modify files on the hard drive, communicate to different server, use AJAX, etc. You can even use flash within your app to make the application look and feel much better. This gives the web developer good access to a desktop.</p>
<p><strong>Server side Scripts using Javascript</strong></p>
<p><strong> </strong></p>
<p><strong><span style="font-weight: normal;">Server side JavaScript has been around for a long time and potentially offers some unique and interesting advantages over other languages (like PHP, ASP, etc) because the same language is spoken by both client and server. There are<a rel="nofollow" href="http://en.wikipedia.org/wiki/Server-side_JavaScript"> numerous attempts</a> to bring server side javascript to the masses.  Server side Javascript has to do much more than what it has to do at the browser level with</span></strong> access to databases, files, and networking, as well as logging, process management, scalability, security, integration APIs, and extensibility. You can even use your own javascript libraries on the server jQuery, dojo, Ext JS, prototype, etc.</p>
<p><strong>Javascript in other places</strong></p>
<p>- Adobe reader (from v3.02) supports Javascript for forms and basic operations. SOAP support has also been included since version 7.0. There is also access to the entire 3D Javascript API. More details on using Javascript is <a rel="nofollow" href="http://www.adobe.com/devnet/acrobat/pdfs/js_developer_guide.pdf">available here</a><br />
- Open office application suite supports Javascript to <a rel="nofollow" href="http://framework.openoffice.org/scripting/release-0.2/javascript-devguide.html">write macros</a>. This move looks like a sensible addon given the usage of VBScript in MS Office suite.<br />
- Apple&#8217;s Dashboard Widgets, Microsoft&#8217;s Gadgets, Yahoo! Widgets, Google Desktop Gadgets are implemented using JavaScript.<br />
- The oddest one in this list will have to be the  <a rel="nofollow" href="http://www.amazon.com/Philips-TSU9400-Pronto-Universal-Control/dp/B000VV9ZJU">Philips Remote Control</a> which uses Javascript</p>
<p><strong>ECMAScript 4 (ECMAScript Harmony)</strong></p>
<p>Javascript has been relatively stable since the third edition of ECMAScript published in 1999. Features under discussion for a future edition originally ECMAScript 4 now ECMAScript Harmony include Classes, a module system, static typing and Optional type annotations, Generators, Iterators, Destructuring assignment, algebraic data types. Well if you think this is ambitious you should see the original ECMAScript 4 which had more semantic and syntactic innovation. Packages, namespaces and early binding from ECMAScript 4 are no longer included for planned releases with ECMAScript Harmony. The intent of these features is partly to better support &#8220;programming in the large&#8221;, and to let programmers sacrifice some of the script&#8217;s ability to be dynamic for performance.</p>
<p>So yes as a web developer who uses Javascript on a daily basis, I am excited to watch Javascript grow and be available in more places.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/rise-of-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Javascript Gotchas listed to help avoid mistakes</title>
		<link>http://www.webdigi.co.uk/blog/2009/javascript-gotchas-listed-to-help-avoid-mistakes/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/javascript-gotchas-listed-to-help-avoid-mistakes/#comments</comments>
		<pubDate>Thu, 21 May 2009 15:53:17 +0000</pubDate>
		<dc:creator>iphp</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[gotchas]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=361</guid>
		<description><![CDATA[A gotcha in programming is something unexpected although a documented feature of a computer system and not a bug. These gotchas throw beginners off Javascript programming and send some people running and screaming. In my opinion, Javascript is one of the most widespread languages as it is available on all browsers but one of the least learned languages.  Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>A gotcha in programming is something unexpected although a documented feature of a computer system and not a bug. These gotchas throw beginners off Javascript programming and send some people running and screaming. In my opinion, Javascript is one of the most widespread languages as it is available on all browsers but one of the least learned languages.  Let&#8217;s start with basic ones.</p>
<p><strong>1. Floating point arithmetic</strong></p>
<p>This can be a major cause of frustration for people who are new to Javascript and are trying to perform some kind of mathematical computation.</p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
alert(0.02 / 0.1);  //0.19999999999999998 &lt;br /&gt;&lt;br /&gt;
alert(1.14 * 100);  //113.99999999999999    ;)&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p>
This is where the Math.round() functions come in handy</p>
<p><span style="font-weight: bold;">2. Plus operator overloading </span></p>
<p>The plus operator stands for both arithmetic operations and also string concatenation. This is convenient if used correctly. Lets take a look</p>
<p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
var msg, one=&quot;1&quot;;&lt;br /&gt;&lt;br /&gt;
msg = 2 + &quot;1&quot;; // msg = &quot;21&quot;&lt;br /&gt;&lt;br /&gt;
msg = 2 + one; // msg = &quot;21&quot;&lt;br /&gt;&lt;br /&gt;
msg = 1 + 1 + 1 + &quot; musketeers&quot;; // msg = &quot;3 musketeers&quot;&lt;br /&gt;&lt;br /&gt;
msg = &quot;Bond &quot; + 0 + 0 + 7; //msg = &quot;Bond 007&quot;  &lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p> <br />
The above behaviour is because the operations are performed left to right. If we use parantheses the behaviour will change based on the order of the string or number in it.</p>
<p><span style="font-weight: bold;">3. Semicolon insertion at line feed</span></p>
<p>Javascript automatically inserts ; at a line feed. Lets see this in action with a simple example:</p>
<p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
function returnSame(a){&lt;br /&gt;&lt;br /&gt;
   return                 //Inserts semi-colon to convert to return;&lt;br /&gt;&lt;br /&gt;
   a                      //a becomes a; - Unreachable&lt;br /&gt;&lt;br /&gt;
}&lt;br /&gt;&lt;br /&gt;
alert(returnSame(2));  //Output is undefined&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p>
The magical semicolon insertion can get things complicated while creating objects using object literals</p>
<p><strong>4. typeof operator</strong></p>
<p>typeof is a unary operator. The results are not one would normally expect. It suprisingly evaluates null to &#8221;object&#8221;. </p>
<p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
var obj={};  //object created using object literal&lt;br /&gt;&lt;br /&gt;
var arr=[];  //array created by array literal&lt;br /&gt;&lt;br /&gt;
alert(typeof(obj));   //object  - Good&lt;br /&gt;&lt;br /&gt;
alert(typeof(arr));   //object  - Bad&lt;br /&gt;&lt;br /&gt;
alert(typeof(null));  //object  - Ugly!  ;)&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p> <br />
It should only be used to distingush objects from other primitive types.</p>
<p><span style="font-weight: bold; ">5. false, null, undefined, NaN, Infinity</span></p>
<p>They stand for different things although they might look similar or at times look redundant. Javascript uses three primitive datatypes numbers, strings and boolean. In addition it has two trivial datatypes undefined and null. Both null and undefined are equal according to the equality operator (==)</p>
<p>
<pre name="code" class="jscript">
 &lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
var a;&lt;br /&gt;&lt;br /&gt;
alert (a);    //undefined&lt;br /&gt;&lt;br /&gt;
alert (1/0);  //Infinity&lt;br /&gt;&lt;br /&gt;
alert (0/0);  //NaN&lt;br /&gt;&lt;br /&gt;
0/0 == 0/0;   //false - a NaN != NaN&lt;br /&gt;&lt;br /&gt;
alert (b);    //error&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p> </p>
<p><span style="font-weight: bold;">6. String replace only replaces first occurence</span></p>
<p>Unlike PHP or other languages, string replace in Javascript only replaces the first occurence of a string by default.</p>
<p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
var nospace = &quot;I dont need spaces&quot;.replace(&quot; &quot;,&quot;_&quot;);&lt;br /&gt;&lt;br /&gt;
alert(nospace);    //I_dont need spaces   - Only first occurence&lt;br /&gt;&lt;br /&gt;
var nospace = &quot;I dont need spaces&quot;.replace(/ /g,&quot;_&quot;);&lt;br /&gt;&lt;br /&gt;
alert(nospace);    //I_dont_need_spaces&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p> </p>
<p><span style="font-weight: bold;">7. ParseInt function</span></p>
<p>This is used to convert a string into an integer. The function does accept two arguments and the second argument specifies the radix. The radix here for decimal is10. If no radix argument is passed the parseInt function tries to guess the base and in this case because the string starts with 0, it is parsed as an <span style="text-decoration: underline;">octal </span>number.</p>
<pre name="code" class="jscript">
&lt;br /&gt;&lt;br /&gt;
&lt;script&gt;&lt;br /&gt;&lt;br /&gt;
var str = &quot;017&quot;;&lt;br /&gt;&lt;br /&gt;
var strInt = parseInt(str);      //strInt = 15  ;)&lt;br /&gt;&lt;br /&gt;
var strInt = parseInt(str,10);   //strInt = 17&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;
</pre>
<p><strong>Please share your Javascript Gotcha&#8217;s using the form below:<br />
<span style="font-weight: normal;">(note use &amp;lt; and &amp;gt;</span> </strong>to get past the comment filter for &lt; and &gt;)</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/javascript-gotchas-listed-to-help-avoid-mistakes/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Avoid Javascript blocking content download on your website during page load</title>
		<link>http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/</link>
		<comments>http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 14:03:00 +0000</pubDate>
		<dc:creator>php-manual</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.webdigi.co.uk/blog/?p=219</guid>
		<description><![CDATA[Around 80% of the end-user response time is spent on the front-end. A fair share of this time is spent on downloading components of the page like scripts, Flash, stylesheets, images etc.  Javascript takes majority of the loading time of a webpage because scripts block parallel downloading and rendering in the page. Even if you do not have [...]]]></description>
			<content:encoded><![CDATA[<p>Around 80% of the end-user response time is spent on the front-end. A fair share of this time is spent on downloading components of the page like scripts, Flash, stylesheets, images etc.  Javascript takes majority of the loading time of a webpage because scripts block parallel downloading and rendering in the page. Even if you do not have a lot of Javascript files to load on your webpage they can still block loading other content on your page while they load.  Lets have a look at how the standard javascript file include method and the script DOM element method in detail below.</p>
<p><strong><span style="text-decoration: underline;">Standard Javascript file include method</span></strong></p>
<pre name="code" class="jscript">

&lt;SCRIPT src=&quot;A.JS&quot; language=&quot;JavaScript/text&quot;&gt;&lt;/SCRIPT&gt;
&lt;SCRIPT src=&quot;B.JS&quot; language=&quot;JavaScript/text&quot;&gt;&lt;/SCRIPT&gt; 

&lt;IMG src=&quot;1.GIF&quot; /&gt;
&lt;IMG src=&quot;2.GIF&quot; /&gt;
&lt;IMG src=&quot;3.GIF&quot; /&gt;
</pre>
<div id="attachment_230" class="wp-caption aligncenter" style="width: 468px"><a rel="attachment wp-att-230" href="http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/document-loading-webpage/"><img class="size-full wp-image-230" title="Javascript blocks the other elements from loading" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/03/document-loading-webpage.png" alt="Javascript blocks the other elements from loading" width="458" height="208" /></a><p class="wp-caption-text">Javascript blocks the other elements from loading (Example)</p></div>
<p><span style="text-decoration: underline;"><strong>Script DOM element method</strong></span></p>
<pre name="code" class="jscript">

var p = g.getElementsByTagName(&quot;HEAD&quot;)[0];
var c = g.createElement(&quot;script&quot;);
c.type= &quot;text/javascript&quot;;
c.onreadystatechange = n;
c.onerror = c.onload = k;
c.src = e;
p.appendChild(C);
</pre>
<div id="attachment_231" class="wp-caption aligncenter" style="width: 468px"><a rel="attachment wp-att-231" href="http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/document-loading-webpage-without-blocking/"><img class="size-full wp-image-231" title="document-loading-webpage-without-blocking" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/03/document-loading-webpage-without-blocking.png" alt="Javascript executed without blocking any element from loading" width="458" height="208" /></a><p class="wp-caption-text">Javascript executed without blocking any element from loading</p></div>
<p>This method creates a DOM element for each Script and then adds the element to the HTML. </p>
<p><strong>NOTE</strong>: </p>
<p>1) Only when the <strong>appendChild </strong>function is called the Javascript will be executed.<br />
2) For inlined code that depends on the Javascript and also for a similar method of <a rel="nofollow" href="http://www.stevesouders.com/blog/" target="_blank">Asynchronous Script Loading &#8211; See Steve Souders blog</a><br />
3) If you go to MSN.com (Alexa top 10 site based on traffic) and hit view source you can see the javacript elements are included by using the script dom element to load the web pages faster. This is a good example of where you can use the script dom element method for certain js files that do not have inlined code dependency. Let us run a <a rel="nofollow" href="http://www.webpagetest.org/" target="_blank">Pagetest waterfall report</a> and you can see the following for MSN.COM</p>
<div id="attachment_282" class="wp-caption aligncenter" style="width: 583px"><img class="size-full wp-image-282" title="no-blocking-msn" src="http://www.webdigi.co.uk/blog/wp-content/uploads/2009/03/no-blocking-msn.png" alt="Javascript loading in MSN does not block" width="573" height="209" /><p class="wp-caption-text">Pagetest Waterfall report of MSN.COM shows no blocking during page load</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.webdigi.co.uk/blog/2009/avoid-javascript-blocking-content-download-on-your-website-during-page-load/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
