Advanced JavaScript


Published on

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Advanced JavaScript

  1. 1. Google+: Blog: Twitter: Advanced JavaScript Techniques, Design patterns, Best practices Mahmoud Tolba @mahmoodfcis
  2. 2. JS brief overview  Developed at Netscpae with the name “LiveScript” at 1996  The key design principles within JavaScript are taken from the Self and Scheme programming languages  Copies many of the names and naming conventions from Java.  Is an interpreted and dynamic language
  3. 3. JavaScript vs. C# vs. other languages JavaScript C# Dynamic Static Interpreted Compiled Client side Server side No plugins required to run it Need plugins to run in client like silverlight
  4. 4. Why JavaScript is important
  5. 5. JavaScript is a dynamic language  You can easily change a variable type dynamically in code so we use the typeof operator to check the data type of a variable  You can add or remove properties from an object dynamically so we can check for them using hasOwnProperty () function
  6. 6. JavaScript is an OOP language  We can create objects in JavaScript either using Constructors or Object literals  We can extend the properties of an object using prototype object  Using String object ( bold(),color(),concat(),replace())  Using Date object (setMoth(),setDate(),setYear(),….)  Using Math object (sqrt(),pi,abs(),floor(),round())
  7. 7. window object  Sits at the top of the JS object hierarchy and represents the browser window.  Used for creating and closing browser windows, displaying alerts, confirmation, setting timeouts  whenever an object method or property is referenced in a script without the object name and dot prefix it is assumed by JavaScript to be a member of the window object  Contains many properties “closed,name,parent,opener,screen,self,top”  Moveto()
  8. 8. Document object  Contains all the HTML elements of the head and body sections of the HTML  Contains may functions and properties “open(),write(),bgcolor,fgcolor”
  9. 9. location object  Is a child object of the window object  Is used to store information about the current window url  Window.location.href=“some url”;  location.protocol - the protocol section of the URL (for example http: or https:)  location.hostname - the hostname (for example  location.port - the HTTP Port number of the URL (for example 80)  - the search portion of the URL (batch=1 in the example above)  location.hash - the anchor name in the URL (#intro in our example)  Has Reload(),replace() methods
  10. 10. history object  Is a child object of the window object  holds information about the URLs visited before and after the current URL  history.length - a property containing the numner of URLs held in the history.  history.go() - takes a postive or negative number as an argument to specify how many changes back or forward in the history to go. For example history.go(-4) is equivalent to pressing the Back buttonm in the browser 4 times.  history.back() - equivalent to pressing the browser Back button (loads the previous page from the history list).  history.forward() - equivalent to pressing the browser Forward button (loads the next page from the history if it exists). 
  11. 11. Array object  Used to create a list, sequence  var arr=new Array(“1”,”2”,3)  Push(),sort(),reverse()
  12. 12. JS cookies  Create cookies using document.cookie=“name=”+value;  Read cookie using document.cookie.split(„=‟)[1]
  13. 13. Closures  A closure is nothing more than a function object with a related scope in which the function’s variables are resolved.  "Think of closures as a kind of regional scope: broader than local but not as broad as global.“  To create a closure, you nest a function inside of a function. That inner function has access to all variables in its parent function‟s scope   
  14. 14. Using object literals to pass optional parameters to function  functions that can accept a large number of optional arguments. Instead of passing the large number of arguments in the conventional fashion, which could unnecessarily complicate the function, you can pass just one argument which ends up being a collection of arguments declared in an object literal
  15. 15. Inheritance  Inheritance is a way to create a class as a specialized version of one or more classes (JavaScript only supports single class inheritance). The specialized class is commonly called the child, and the other class is commonly called the parent. In JavaScript you do this by assigning an instance of the parent class to the child class, and then specializing it. In modern browsers you can also use Object.create to implement inheritance
  16. 16. Callbacks  Passing a function as an argument is easy
  17. 17. JavaScript libraries  There are many JavaScript libraries and resources.  Jquery,Node.js, Bootstrap, Backbone, knockout are popular JavaScript libraries
  18. 18. Knockout.js  Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user‟s actions or when an external data source changes), KO can help you implement it more simply and maintainably  Headline features:  Elegant dependency tracking - automatically updates the right parts of your UI whenever your data model changes.  Declarative bindings - a simple and obvious way to connect parts of your UI to your data model. You can construct a complex dynamic UIs easily using arbitrarily nested binding contexts.  Trivially extensible - implement custom behaviors as new declarative bindings for easy reuse in just a few lines of code.  Additional benefits:  Pure JavaScript library - works with any server or client-side technology  Can be added on top of your existing web application without requiring major architectural changes  Compact - around 13kb after gzipping  Works on any mainstream browser (IE 6+, Firefox 2+, Chrome, Safari, others)  Comprehensive suite of specifications (developed BDD-style) means its correct functioning can easily be verified on new browsers and platforms  
  19. 19. JavaScriptMvc  Is an open-source rich Internet application framework based on jQuery and OpenAjax. It extends those libraries with a model–view– controller architecture and tools for testing and deployment. As it does not depend on server components, it can be combined with any web service interface and server-side language like ASP.NET, Java, Perl, PHP, Python, or Ruby  For more info
  20. 20. Backbone.js  Backbone.js is basically an uber-light framework that allows you to structure your Javascript code in anMVC(Model, View, Controller) fashion where...  Model is part of your code that retrieves and populates the data,  View is the HTML representation of this model(views change as models change, etc)  and Controller that in this case allows you to save the state of your javascript application via a hashbang url, for example:   
  21. 21. Angularjs  A toolset based on extending the HTML vocabulary for your application  
  22. 22.  is an MVC library for Javascript that lets you write maintainable and reusable browser code without the verbose or infrastructural overhead found in other MVC libraries. The goal is to enable developers to write web apps at least as quickly as with jQuery, while simplifying long-term maintainability through MVC objects. 
  23. 23.  Sencha Ext JS is the industry's most powerful desktop application development platform with unparalleled cross-browser compatibility, advanced MVC architecture, plugin-free charting, and modern UI widgets 
  24. 24.   is a JavaScript library that detects HTML5 and CSS3 features in the user‟s browser  runs quickly on page load to detect features; it then creates a JavaScript object with the results, and adds classes to the HTML element for you to key your CSS on 
  25. 25.  is an asynchronous conditional resource loader that's super-fast, and allows you to load only the scripts that your users need 
  26. 26. Winjs  Is a JavaScript library for building windows 8 store apps  
  27. 27. LimeJS  Is a HTML5 game framework for building fast, native-experience games for all modern touchscreens and desktop browsers 
  28. 28. Lungo Framework  A framework based on HTML5 fordevelopers who want to design, buildand share cross device applications 
  29. 29.  Breeze is a JavaScript library that helps you manage data in rich client applications. If you store data in a database, query and save those data as complex object graphs, and share these graphs across multiple screens of your JavaScript client, Breeze is for you  
  30. 30.  is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript 
  31. 31.  jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice. 
  32. 32.  A unified, HTML5-based user interface system for all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design. 
  33. 33.  Is A JavaScript Unit Testing framework.  is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code 
  34. 34. Jo Framework for HTML5  he simple app framework for HTML5  For iOS, Android, webOS, BlackBerry, Chrome OS & anything else with HTML5  Widgets, lists and scrolling goodness using JavaScript & CSS3  Make native mobile apps or web apps with the same code  Works great with PhoneGap   See a demo at
  35. 35. DHTMLX Touch  DHTMLX Touch is a free open source JavaScript library for building HTML5-based mobile web apps. It's not just a set of UI widgets, but a complete framework that allows you to create eyecatching, robust web applications that run on iOS, Android, and other mobile platforms 
  36. 36.  MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API 
  37. 37.  Prototype takes the complexity out of client-side web programming. Built to solve real-world problems, it adds useful extensions to the browser scripting environment and provides elegant APIs around the clumsy interfaces of Ajax and the Document Object Model 
  38. 38. 
  39. 39.  Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices 
  40. 40. Finally, Thanks to JavaScript