Exam 70 480 Advanced Javascript at Jinal Desai .NET

844 views

Published on

The article is shortly describing some advanced HTML5 topics like Promises, Web Workers and Web Sockets. Rather than to re-writing from scratch about the details, I write the fundamentals about the topics and then give links for detail study.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
844
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Exam 70 480 Advanced Javascript at Jinal Desai .NET

  1. 1. Articles from Jinal Desai .NETExam 70-480 Advanced Javascript2013-01-26 07:01:02 Jinal DesaiThe article is shortly describing some advanced HTML5 topics like Promises, WebWorkers and Web Sockets. Rather than to re-writing from scratch about the details,I write the fundamentals about the topics and then give links for detail study.PromisesPromise is a pattern implemented in Javascript which gives some advantages overAsynchronous Programming in Javascript.When we execute asynchronous call using “XMLHttpRequest”, the execution doesnot follow linear path. You need not to wait for the call to complete execution, youjust carry out with your next task and the asynchronous call will be executing inbackground. One thing you need to handle is successful completion and errorhandling.function loadFile(){ var xhr, results, url; url = "http://jinaldesai.net/sitemap.xml"; xhr = new XMLHttpRequest(); xhr.open(GET, url, true); //last argument denotes the call is asynchronous xhr.onload = function(e){ if(this.status == 200) { results = this.responseText; } }; xhr.onerror = function(e){ handleError(e); } xhr.send();}function handleError(err){ //handle error}In most of the scenarios you want to pass the result into another ajax request whichintroduces complexity into asynchronous call. When you write code for NestedCallbacks, the code grows clumsy. For handling error of nested callbacks, we needto check at several places to see if an error occured.Promise pattern reduces such complexity and clumsiness. For examplevar results = loadFile().then(filterFileValues, handleError). then(sortResultset, handleError).done(doFinalStuffHere);printResults(results);Promises are in one of the three states at any time: unfulfilled, resolved or rejected.Promise pattern is also available with jQuery and Dojo Toolkit.For more information about Promises refer following links.Promises and future in JavascriptAsynchronous Programming in JavaScript with PromisesPromise Pipelines in JavascriptJavascript PromisesWeb Workers
  2. 2. Web workers allows to run javascript in background, disregards of other scriptsrunning or screen jam. So performance will not be affected. So, if you need to runsome process which can run in background independently then use web worker.With web workers you can bring threading concept to life in Javascript. Executingjavascript in background with separate js file is just like running separate thread. Theonly thing you need to take care is the communication carried out between yourcurrent thread(calling file) and the thread you have initiated with web workerprocess.Following are some nice examples of Web Workers for beginner.W3SchoolHtml 5 RocksWeb SocketsIt is a technique for two way communication over TCP, just like client-server. Youcan implement kind of PUSH technology using web sockets. You can even developchatting application, mail client application and many such applications where twocommunication involved between two processes resides on different server.I have found nice tutorial on net tuts plus.Net Tuts Plus Web Socket TutorialConclusionHTML5 come up with many new javascript things like Promises, Web Workers,Web Sockets, Storage APIs, Geolocation API and lot more. In this article I shortlydescribed Promises, Web Workers and Web Sockets introduction with some usefullinks. Hope it will helpful to get basic idea of Promises, Web Workers and WebSockets.

×