SlideShare uma empresa Scribd logo
1 de 40
Google+:
Blog:
Twitter:

Advanced JavaScript
Techniques, Design patterns, Best practices

Mahmoud Tolba
Mahmoodfcis.wordpress.com
@mahmoodfcis
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
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
Why JavaScript is important
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
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())
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()
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”
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 www.techotopia.com)
 location.port - the HTTP Port number of the URL (for example 80)
 location.search - 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
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).


Array object

 Used to create a list, sequence
 var arr=new Array(“1”,”2”,3)
 Push(),sort(),reverse()
JS cookies

 Create cookies using document.cookie=“name=”+value;
 Read cookie using document.cookie.split(„=‟)[1]
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
 http://ejohn.org/apps/learn/#49
 http://ejohn.org/apps/learn/#50

 http://ejohn.org/apps/learn/#51
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
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
Callbacks

 Passing a function as an argument is easy
JavaScript libraries

 There are many JavaScript libraries and resources.
 Jquery,Node.js, Bootstrap, Backbone, knockout are popular JavaScript libraries
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



http://knockoutjs.com/examples/helloWorld.html



http://knockoutjs.com/index.html
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 http://javascriptmvc.com/
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: http://twitter.com/#search?q=backbone.js
 http://backbonejs.org/
 http://backbonetutorials.com/
 http://www.asp.net/single-page-application/overview/templates/backbonejs-template
Angularjs

 A toolset based on extending the HTML
vocabulary for your application
 http://angularjs.org/
 http://docs.angularjs.org/tutorial
 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.
 http://agilityjs.com/
 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
 http://www.sencha.com/products/extjs
 http://modernizr.com/
 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
 http://webdesignernotebook.com/css/how-to-use-modernizr/
 is an asynchronous conditional resource loader that's super-fast, and allows you to load only
the scripts that your users need
 http://yepnopejs.com/
Winjs

 Is a JavaScript library for building windows 8 store apps
 http://winjstoolkit.codeplex.com
 http://dev.bennage.com/blog/2012/08/01/a-brief-introduction-to-winjs/
LimeJS

 Is a HTML5 game framework for building fast, native-experience games for all modern
touchscreens and
desktop browsers
 http://www.limejs.com/
Lungo Framework

 A framework based on HTML5 fordevelopers who want to design, buildand share cross
device applications
 http://www.lungo.tapquo.com/
 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
 http://www.breezejs.com/home
 http://www.johnpapa.net/spajs04/
 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
 http://jquery.com/
 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.
 http://jqueryui.com/
 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.
 http://jquerymobile.com/
 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
 http://qunitjs.com/
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
 http://joapp.com/
 See a demo at http://joapp.com/live/samples/test.html
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
 http://dhtmlx.com/touch/
 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
 http://mootools.net/
 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
 http://prototypejs.org/
 http://wijmo.com/demo/explore/
 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
 http://nodejs.org/
Finally, Thanks to JavaScript

Mais conteúdo relacionado

Mais procurados

Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design PatternsDerek Brown
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptIngvar Stepanyan
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Nilesh Jayanandana
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax BasicsRichard Paul
 
Consuming Web Services with Swift and Rx
Consuming Web Services with Swift and RxConsuming Web Services with Swift and Rx
Consuming Web Services with Swift and RxGuillermo Gonzalez
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 

Mais procurados (20)

Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScript
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
Consuming Web Services with Swift and Rx
Consuming Web Services with Swift and RxConsuming Web Services with Swift and Rx
Consuming Web Services with Swift and Rx
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Javascript tid-bits
Javascript tid-bitsJavascript tid-bits
Javascript tid-bits
 

Destaque

Windows Communication Foundation
Windows Communication FoundationWindows Communication Foundation
Windows Communication FoundationMahmoud Tolba
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity FrameworkMahmoud Tolba
 
Disruptive technologies and the implications for University Information Servi...
Disruptive technologies and the implications for University Information Servi...Disruptive technologies and the implications for University Information Servi...
Disruptive technologies and the implications for University Information Servi...diharrison
 
The role of the central IT Services organisation in a Web 2.0 world - paper
The role of the central IT Services organisation in a Web 2.0 world - paperThe role of the central IT Services organisation in a Web 2.0 world - paper
The role of the central IT Services organisation in a Web 2.0 world - paperdiharrison
 
So that's it for it services, or is it?
So that's it for it services, or is it?So that's it for it services, or is it?
So that's it for it services, or is it?diharrison
 
Universities And Social Networking: making sense out of nonsense
Universities And Social Networking: making sense out of nonsenseUniversities And Social Networking: making sense out of nonsense
Universities And Social Networking: making sense out of nonsensediharrison
 

Destaque (6)

Windows Communication Foundation
Windows Communication FoundationWindows Communication Foundation
Windows Communication Foundation
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Disruptive technologies and the implications for University Information Servi...
Disruptive technologies and the implications for University Information Servi...Disruptive technologies and the implications for University Information Servi...
Disruptive technologies and the implications for University Information Servi...
 
The role of the central IT Services organisation in a Web 2.0 world - paper
The role of the central IT Services organisation in a Web 2.0 world - paperThe role of the central IT Services organisation in a Web 2.0 world - paper
The role of the central IT Services organisation in a Web 2.0 world - paper
 
So that's it for it services, or is it?
So that's it for it services, or is it?So that's it for it services, or is it?
So that's it for it services, or is it?
 
Universities And Social Networking: making sense out of nonsense
Universities And Social Networking: making sense out of nonsenseUniversities And Social Networking: making sense out of nonsense
Universities And Social Networking: making sense out of nonsense
 

Semelhante a Advanced JavaScript

Technology Stack Discussion
Technology Stack DiscussionTechnology Stack Discussion
Technology Stack DiscussionZaiyang Li
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Lookrumsan
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit frameworkSunil Kumar
 
Sofea and SOUI - Web future without web frameworks
Sofea and SOUI - Web future without web frameworksSofea and SOUI - Web future without web frameworks
Sofea and SOUI - Web future without web frameworksAndré Neubauer
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | IntroductionJohnTaieb
 
Survive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksSurvive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksJuho Vepsäläinen
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web ApplicationSachin Walvekar
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Crash Course HTML/Rails Slides
Crash Course HTML/Rails SlidesCrash Course HTML/Rails Slides
Crash Course HTML/Rails SlidesUdita Plaha
 
WEB MODULE 3.pdf
WEB MODULE 3.pdfWEB MODULE 3.pdf
WEB MODULE 3.pdfDeepika A B
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moiblemarkuskobler
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Beat Signer
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-frameworkWBUTTUTORIALS
 
State of modern web technologies: an introduction
State of modern web technologies: an introductionState of modern web technologies: an introduction
State of modern web technologies: an introductionMichael Ahearn
 

Semelhante a Advanced JavaScript (20)

Technology Stack Discussion
Technology Stack DiscussionTechnology Stack Discussion
Technology Stack Discussion
 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
 
Sofea and SOUI - Web future without web frameworks
Sofea and SOUI - Web future without web frameworksSofea and SOUI - Web future without web frameworks
Sofea and SOUI - Web future without web frameworks
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Html5
Html5Html5
Html5
 
Survive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and TricksSurvive JavaScript - Strategies and Tricks
Survive JavaScript - Strategies and Tricks
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web Application
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Crash Course HTML/Rails Slides
Crash Course HTML/Rails SlidesCrash Course HTML/Rails Slides
Crash Course HTML/Rails Slides
 
Career guideline
Career guidelineCareer guideline
Career guideline
 
WEB MODULE 3.pdf
WEB MODULE 3.pdfWEB MODULE 3.pdf
WEB MODULE 3.pdf
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moible
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
 
State of modern web technologies: an introduction
State of modern web technologies: an introductionState of modern web technologies: an introduction
State of modern web technologies: an introduction
 

Mais de Mahmoud Tolba

The passionate programmer
The passionate programmerThe passionate programmer
The passionate programmerMahmoud Tolba
 
Introduction to SAP, Systems, Applications
Introduction to SAP, Systems, ApplicationsIntroduction to SAP, Systems, Applications
Introduction to SAP, Systems, ApplicationsMahmoud Tolba
 
Developing cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaDeveloping cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaMahmoud Tolba
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllersMahmoud Tolba
 
ASP.NET MVC4 Overview
ASP.NET MVC4 OverviewASP.NET MVC4 Overview
ASP.NET MVC4 OverviewMahmoud Tolba
 
Top emerging technologies
Top emerging technologiesTop emerging technologies
Top emerging technologiesMahmoud Tolba
 

Mais de Mahmoud Tolba (8)

The passionate programmer
The passionate programmerThe passionate programmer
The passionate programmer
 
Introduction to SAP, Systems, Applications
Introduction to SAP, Systems, ApplicationsIntroduction to SAP, Systems, Applications
Introduction to SAP, Systems, Applications
 
AngularJS
AngularJSAngularJS
AngularJS
 
Developing cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaDeveloping cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache Cordova
 
JQuery Overview
JQuery OverviewJQuery Overview
JQuery Overview
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllers
 
ASP.NET MVC4 Overview
ASP.NET MVC4 OverviewASP.NET MVC4 Overview
ASP.NET MVC4 Overview
 
Top emerging technologies
Top emerging technologiesTop emerging technologies
Top emerging technologies
 

Último

4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 

Último (20)

4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 

Advanced JavaScript

  • 1. Google+: Blog: Twitter: Advanced JavaScript Techniques, Design patterns, Best practices Mahmoud Tolba Mahmoodfcis.wordpress.com @mahmoodfcis
  • 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. 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. Why JavaScript is important
  • 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. 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. 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. 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. 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 www.techotopia.com)  location.port - the HTTP Port number of the URL (for example 80)  location.search - 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. 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. Array object  Used to create a list, sequence  var arr=new Array(“1”,”2”,3)  Push(),sort(),reverse()
  • 12. JS cookies  Create cookies using document.cookie=“name=”+value;  Read cookie using document.cookie.split(„=‟)[1]
  • 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  http://ejohn.org/apps/learn/#49  http://ejohn.org/apps/learn/#50  http://ejohn.org/apps/learn/#51
  • 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. 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. Callbacks  Passing a function as an argument is easy
  • 17. JavaScript libraries  There are many JavaScript libraries and resources.  Jquery,Node.js, Bootstrap, Backbone, knockout are popular JavaScript libraries
  • 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  http://knockoutjs.com/examples/helloWorld.html  http://knockoutjs.com/index.html
  • 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 http://javascriptmvc.com/
  • 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: http://twitter.com/#search?q=backbone.js  http://backbonejs.org/  http://backbonetutorials.com/  http://www.asp.net/single-page-application/overview/templates/backbonejs-template
  • 21. Angularjs  A toolset based on extending the HTML vocabulary for your application  http://angularjs.org/  http://docs.angularjs.org/tutorial
  • 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.  http://agilityjs.com/
  • 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  http://www.sencha.com/products/extjs
  • 24.  http://modernizr.com/  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  http://webdesignernotebook.com/css/how-to-use-modernizr/
  • 25.  is an asynchronous conditional resource loader that's super-fast, and allows you to load only the scripts that your users need  http://yepnopejs.com/
  • 26. Winjs  Is a JavaScript library for building windows 8 store apps  http://winjstoolkit.codeplex.com  http://dev.bennage.com/blog/2012/08/01/a-brief-introduction-to-winjs/
  • 27. LimeJS  Is a HTML5 game framework for building fast, native-experience games for all modern touchscreens and desktop browsers  http://www.limejs.com/
  • 28. Lungo Framework  A framework based on HTML5 fordevelopers who want to design, buildand share cross device applications  http://www.lungo.tapquo.com/
  • 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  http://www.breezejs.com/home  http://www.johnpapa.net/spajs04/
  • 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  http://jquery.com/
  • 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.  http://jqueryui.com/
  • 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.  http://jquerymobile.com/
  • 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  http://qunitjs.com/
  • 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  http://joapp.com/  See a demo at http://joapp.com/live/samples/test.html
  • 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  http://dhtmlx.com/touch/
  • 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  http://mootools.net/
  • 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  http://prototypejs.org/
  • 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  http://nodejs.org/
  • 40. Finally, Thanks to JavaScript