SlideShare a Scribd company logo
Sencha [ExtJS]: Object Oriented JavaScript Rohan Chandane www.slideshare.net/rohan.chandane
Namespace Class Constructor Properties Methods/ Functions Object Inheritance Object Oriented Approach
Defining a namespace in Sencha (ExtJS) class gives unique name for the JavaScript Class helps in organizing JavaScript code declaring namespace in ExtJS/ Senchaeg Ext.ns("com.company.app"); Namespace
Two ways to write custom class in ExtJS 1st way Class Ext.ns("com.company.app"); (function(){         // class definition     var JSClass = Ext.extend(Object,{     .     .     })// end of class definition      com.company.app.JSClass = JSClass; })();
2nd way Continued..  var com.company.app.JSClass = Ext.extend(Object,{     .     .  })// end of class definition
Constructor Ext.ns("com.company.app"); (function(){     varJSClass = Ext.extend(Object,{         //constructor function, this function will get 	         	//execute when object is created for the class     	constructor: function(config){         	//console.log("JSClass constructor");         	Ext.apply(this, config)     	}     .     .     })     com.company.app.JSClass = JSClass ; })();
Constructor, function, attribute Ext.ns("com.company.app"); (function(){     var JSClass = Ext.extend(Object,{         //constructor function         constructor: function(config){             //console.log("constructor called" );             Ext.apply(this, config)         },     	// attribute     	color: 'red',     	// some function    	moveBlock: function(newX, newY, myDiv1){         	    Ext.get(myDiv1).moveTo(newX, newY, true); 	}     	.     })     com.company.app.JSClass = JSClass; })();
Create Object & Call a function // it need to include file JSClass.js in HTML, if it's  // calling from HTML // create a object of the class varobj = new com.company.app.JSClass(); obj.moveBlock('0','-250','searchDiv');
Inheritance Ext.ns("com.company.app");(function(){     varNewJSClass = Ext.extend(com.company.app.JSClass,{     .     .     .     })    com.company.app.NewJSClass = NewJSClass; })();
Using extended class Ext.ns("com.company.app");(function(){     varNewJSClass = Ext.extend(com.company.app.JSClass ,{         color: 'blue',         constructor: function(config){            JSClass.superclass.constructor.apply(this, arguments)        },         // method override         moveBlock: function(newY, myDiv1){             Ext.get(myDiv1).moveTo(0, newY, true);         }     })    com.company.app.NewJSClass = NewJSClass; })();
Module Pattern: POJO like class Ext.ns("com.company.app"); (function(){     var JSClass = Ext.extend(Object,{         //constructor function     constructor: function(config){         Ext.apply(this, config)     }     // class variable     ,value1: null     ,value2: null     	// getter, setter     ,getValue1:function(){         return value1;     }    ,setValue1: function(val){         this.value1 = val;     }            })    com.company.app.JSClass = JSClass; })();
Ext.apply simply copies data members from a source object to a destination object and allows you to provide default values Defaults are optional, when there is defaults it does this Run the next example in firebug, to understand it quickly Ext.apply() Syntax: Ext.apply(receivingObject, sendingObject, defaults) Ext.apply(receivingObject, defaults); Ext.apply(receivingObject, sendingObject);
Continued.. var obj1 = {firstName: 'Rohan', lastName: 'Chandane'} console.log(obj1) //{firstName: 'Rohan', lastName: 'Chandane'} var obj2 = {job:'Dev', lang:'JavaScript', c: function(){}} console.log(obj2) // {job:'Dev', lang:'JavaScript' c: function(){}} var obj3 = Ext.apply(obj2, obj1, {newVar: 'new value'}) console.log(obj3) // {firstName: 'Rohan', lastName: 'Chandane', job:'Dev', lang:'JavaScript' c: function(){}, newVar: 'new value'} // replacing job value here var obj3 = Ext.apply(obj2, obj1, {job: 'new value'}) console.log(obj3) // {firstName: 'Rohan', lastName: 'Chandane', job:'new value', lang:'JavaScript' c: function(){}}
Then what is the difference between Ext.apply() and Ext.extend() Ext.extend will inherit a superclass's data members and methods as well as add a superclass property and an override method. Ext.apply simply copies data members Continued..
Modifying constructor in Module pattern to check Ext.apply() Adding console.log in JSClassto print config Create object of JSClassclass Continued.. constructor: function(config){ Ext.apply(this, config);     console.log(this.newVar) } // creating object of JSClass (Module Pattern) var config = { varnewVar = “Rohan” } varnewObj = com.company.app.JSClass(config); // Rohan
Extras of OO JavaScript
JavaScript is dynamic object oriented language Properties and Function can be added and removed at run time Function can be moved from one object to another Example: Continued.. varobj = new Object();propertyName="firstName";propertyValue="Rohan"; console.log(obj.firstName);// undefinedeval("obj ."+propertyName+"='"+propertyValue+"'");console.log(obj.firstName);// Rohan delete (obj.firstName)console.log(obj.firstName)// undefined
Basic Project Setup
Ajax application can be divided in two part Ajax Deluxe Applications feel similar to a desktop app Its fully Ajax + JavaScript driven application Scalable and for big applications  Ajax Lite Application/website feels more like a conventional web app Ajax is used for small operations like validation with server Useful only for small, quick functionality Web 2 App types
Here, lets take a look at Ajax Deluxe first  Continued..
Project structure AppName | |_lib |   |_com |   |   |_company |   |       |_myapp |   |            |_package1 |   |                |_Main.js  |   |            |_package2 |   |_ext |       |_(Extracted ExtJS lib & folders) |       |_(...) ||_assets |   |_css |   |_img| |_Index.html
Index.html Version 1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">     <title>Basic Setup</title>     <!-- Bring in the ExtJs Libraries and CSS -->     <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>     <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>     <script type="text/javascript" src="lib/ext/ext-all.js"></script>            <!-- Place the page specific js here -->        <script type="text/javascript">              Ext.onReady(function(){             // Mandatory: need to add this spacer             Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif';             // alert message box to check if ExtJS loaded             Ext.MessageBox.alert("Hello Example","Hello, Rohan! ExtJS loaded successfully!");         });        </script>          </head>     <body></body> </html>
Index.html Version 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">     <title>Basic Setup</title>     <!-- Bring in the ExtJs Libraries and CSS -->     <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>     <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>     <script type="text/javascript" src="lib/ext/ext-all.js"></script>            <!-- Place the page specific js here -->     <script type="text/javascript" src="lib/com/company/myapp/package1/Main.js "> </script>          </head>     <body></body> </html>
Main.js  Version 2: Ext.onReady(function(){     // Mandatory: need to add this spacer /*[relative path to..]*/     Ext.BLANK_IMAGE_URL = ‘lib/ext/resources/images/default/s.gif';     Ext.QuickTips.init();     // alert message box to check if ExtJS loaded     Ext.MessageBox.alert("Hello Example","Hello, Rohan! ExtJS loaded successfully!"); });
Now, for creating a Ajax Deluxe App from our existing setup It needs to use Border Layout (Viewport) We will edit Main.js and will add Ext.Viewport() As border layout has north, south, west, east & center region, We will add those using Ext.Panel() So Main.js will look like this - Continued..
Main.js with Ext.Viewport() Ext.onReady(function(){     // Mandatory: need to add this spacer /*[relative path to..]*/ Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif'; Ext.QuickTips.init();     // viewport panels  varnorthPanel = new Ext.Panel({ 	id: 'north-panel', height : 50,region: 'north', border: false, title:'Top Panel' }); varsouthPanel = new Ext.Panel({ 	id: 'south-panel', height : 200, region: 'south', title : 'South Panel', 	collapsible: true, collapsed: true }); varwestPanel = new Ext.Panel({      	id: 'west-panel', layout: 'fit', width: 250, region: 'west', title: 	'Navigation', collapsible: true      }); varcenterPanel = new Ext.Panel({      	region: 'center' ,layout: 'fit', title: 'Content Panel'      }); // viewport new Ext.Viewport({ id: 'id-viewport'     ,layout : 'border'     ,items  : [northPanel,southPanel,westPanel,centerPanel] }); });
Preview: using Viewport
Here is object oriented programming with JavaScript We will create View, ViewLayout.js Class, which will render this Border Layout. We will modify Main.js and will create ViewLayout.js in directory package2 Add entry in Index.html for ViewLayout.js, Main.js OO
Index.html <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">     <title>Basic Setup</title>     <!-- Bring in the ExtJs Libraries and CSS -->     <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>     <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>     <script type="text/javascript" src="lib/ext/ext-all.js"></script>    <!-- Place the page specific js here --> <script type="text/javascript" src="lib/com/company/hello/package2/Main.js"></script>    <script type="text/javascript" src="lib/com/company/hello/package2/ViewLayout.js"> </script> </head>
ViewLayout.js Ext.ns("com.company.hello.package2"); (function(){ varViewLayout = Ext.extend(Object,{         constructor: function(config){ Ext.apply(this, config);         },         // creating page layout, code goes here         /* public */ createLayout: function(){         // viewport panels  varnorthPanel = new Ext.Panel({ 	id: 'north-panel', height : 50,region: 'north', border: false, title:‘ Top Panel' }); varsouthPanel = new Ext.Panel({ 	id: 'south-panel', height : 200, region: 'south', title : 'South Panel', collapsible: true, collapsed: true    }); varwestPanel = new Ext.Panel({ 	id: 'west-panel', layout: 'fit', width: 250, region: 'west', title: 'Navigation',    collapsible: true    }); varcenterPanel = new Ext.Panel({ 	region: 'center' ,layout: 'fit', title: 'Content Panel' }); code continues..
Continued..         // viewport         new Ext.Viewport({             id: 'id-viewport'             ,layout : 'border'             ,items  : [northPanel, southPanel, westPanel, centerPanel]         }); }     });     com.company.hello.package2.ViewLayout = ViewLayout; })();
Main.js Ext.onReady(function(){     // Mandatory: need to add this spacer /*[relative path to..]*/ Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif'; Ext.QuickTips.init();     // main execution start here, user defined function varonModuleLoad = function(){ varviewLayout = new com.company.hello.package2.ViewLayout(); viewLayout.createLayout();         }     // main starting point onModuleLoad(); });
Preview: using OO, ViewPort
Design Patterns with ExtJS
Singleton Ext.ns("com.netapp.hello.package1"); 	(function() { varSingletonModel = Ext.extend(Object, { 			_instance : null 		,constructor : function() { 			console.log("Singleton constructor called : " + this.getInstance()); 		} 		,getInstance : function() { 			if (this._instance === null) { this._instance = this.createInstance(); 			} 			return this._instance; 		} 		,createInstance : function() { 			return 10; 		} 	}); 	com.netapp.hello.package1.SingletonModel = SingletonModel; })()
Module Ext.ns("com.netapp.hello.package1"); 	(function(){ varModulePattern = Ext.extend(Object,{ name:"Rohan" 		,constructor:function(){ 			console.log("constrcutor"); 		} ,getName:function(){ 			this.name; 		} ,setName:function(val){ 			this.name = val; 		} 	}); 	com.netapp.hello.package2.ModulePattern = ModulePattern; })()
Performance with ExtJS
Use reusable code  Object Oriented Approach  Modularize code Do not access DOM frequently Its computational heavy code Use Lazy loading, wherever possible But avoid heavy nesting  Use of event delegation Events should be assigned to a smaller subset of the document/element, rather than each individual element, this uses JavaScript’s event bubbling notion.  this approach takes less memory in browser Continued..
Use of JavaScript minification, obfuscater YUI compressor, Linters  (jsonlint.com, jslint.com) Use of efficient programming practices in JavaScript  Example: String manipulation - instead of string concatenation using ‘+’ operator, use of array’s .join() function, this way it will be better garbage collected. Cross Browser Scripting: using web standards, feature detection techniques instead browser detection technique and browser specific code Remove listeners which are not in use anymore Continued..
Loops are heavy, it can be optimized by using simple techniquesIn for loop, whenever reading length of array, store it in some variable instead of reading it again and again using array.length Avoid creating lot of HTML code with JavaScript Continued..
I will update these notes periodically with my experiments,  stay tuned.. Note
References http://www.jslog.com http://ajaxpatterns.org http://www.sencha.com/forum/ http://edspencer.net http://code.google.com/p/v8/ http://www.cherny.com/

More Related Content

What's hot

WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
Yakov Fain
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
Ivano Malavolta
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
Christian Heilmann
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
Mariusz Nowak
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
Rich Helton
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
Phan Tuan
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
ygv2000
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
Wen-Tien Chang
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedBG Java EE Course
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
Doeun KOCH
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
Vivek Bhusal
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
Yakov Fain
 
Wt unit 4
Wt unit 4Wt unit 4
Wt unit 4
team11vgnt
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext jsMats Bryntse
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 

What's hot (20)

WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
RequireJS & Handlebars
RequireJS & HandlebarsRequireJS & Handlebars
RequireJS & Handlebars
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Wt unit 4
Wt unit 4Wt unit 4
Wt unit 4
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 

Similar to Sencha / ExtJS : Object Oriented JavaScript

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETMats Bryntse
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
Ahmed Assaf
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
bcruhl
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
Luca Garulli
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
Wildan Maulana
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Even Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax ExperienceEven Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax Experience
Steve Souders
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsZohar Arad
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
Jady Yang
 

Similar to Sencha / ExtJS : Object Oriented JavaScript (20)

eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Java scriptforjavadev part2a
Java scriptforjavadev part2aJava scriptforjavadev part2a
Java scriptforjavadev part2a
 
Javascript
JavascriptJavascript
Javascript
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
backend
backendbackend
backend
 
backend
backendbackend
backend
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Even Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax ExperienceEven Faster Web Sites at The Ajax Experience
Even Faster Web Sites at The Ajax Experience
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
 

More from Rohan Chandane

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!
Rohan Chandane
 
Agile & Scrum, Certified Scrum Master! Crash Course
Agile & Scrum,  Certified Scrum Master! Crash CourseAgile & Scrum,  Certified Scrum Master! Crash Course
Agile & Scrum, Certified Scrum Master! Crash Course
Rohan Chandane
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
Rohan Chandane
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so farRohan Chandane
 
Backbone js
Backbone jsBackbone js
Backbone js
Rohan Chandane
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideRohan Chandane
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)
Rohan Chandane
 
Parsing XML in J2ME
Parsing XML in J2MEParsing XML in J2ME
Parsing XML in J2ME
Rohan Chandane
 
J2ME RMS
J2ME RMSJ2ME RMS
J2ME RMS
Rohan Chandane
 
J2ME IO Classes
J2ME IO ClassesJ2ME IO Classes
J2ME IO Classes
Rohan Chandane
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2ME
Rohan Chandane
 

More from Rohan Chandane (13)

Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!Agile Maturity Model, Certified Scrum Master!
Agile Maturity Model, Certified Scrum Master!
 
Agile & Scrum, Certified Scrum Master! Crash Course
Agile & Scrum,  Certified Scrum Master! Crash CourseAgile & Scrum,  Certified Scrum Master! Crash Course
Agile & Scrum, Certified Scrum Master! Crash Course
 
An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications An Introduction To Testing In AngularJS Applications
An Introduction To Testing In AngularJS Applications
 
Agile :what i learnt so far
Agile :what i learnt so farAgile :what i learnt so far
Agile :what i learnt so far
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Node js
Node jsNode js
Node js
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)Blogger's Park Presentation (Blogging)
Blogger's Park Presentation (Blogging)
 
J2ME GUI Programming
J2ME GUI ProgrammingJ2ME GUI Programming
J2ME GUI Programming
 
Parsing XML in J2ME
Parsing XML in J2MEParsing XML in J2ME
Parsing XML in J2ME
 
J2ME RMS
J2ME RMSJ2ME RMS
J2ME RMS
 
J2ME IO Classes
J2ME IO ClassesJ2ME IO Classes
J2ME IO Classes
 
Java2 MicroEdition-J2ME
Java2 MicroEdition-J2MEJava2 MicroEdition-J2ME
Java2 MicroEdition-J2ME
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 

Sencha / ExtJS : Object Oriented JavaScript

  • 1. Sencha [ExtJS]: Object Oriented JavaScript Rohan Chandane www.slideshare.net/rohan.chandane
  • 2. Namespace Class Constructor Properties Methods/ Functions Object Inheritance Object Oriented Approach
  • 3. Defining a namespace in Sencha (ExtJS) class gives unique name for the JavaScript Class helps in organizing JavaScript code declaring namespace in ExtJS/ Senchaeg Ext.ns("com.company.app"); Namespace
  • 4. Two ways to write custom class in ExtJS 1st way Class Ext.ns("com.company.app"); (function(){    // class definition     var JSClass = Ext.extend(Object,{     .     .     })// end of class definition      com.company.app.JSClass = JSClass; })();
  • 5. 2nd way Continued.. var com.company.app.JSClass = Ext.extend(Object,{     .     .  })// end of class definition
  • 6. Constructor Ext.ns("com.company.app"); (function(){     varJSClass = Ext.extend(Object,{         //constructor function, this function will get //execute when object is created for the class      constructor: function(config){          //console.log("JSClass constructor");          Ext.apply(this, config)      }     .     .     })     com.company.app.JSClass = JSClass ; })();
  • 7. Constructor, function, attribute Ext.ns("com.company.app"); (function(){     var JSClass = Ext.extend(Object,{         //constructor function      constructor: function(config){          //console.log("constructor called" );          Ext.apply(this, config)      },      // attribute      color: 'red',      // some function     moveBlock: function(newX, newY, myDiv1){          Ext.get(myDiv1).moveTo(newX, newY, true); }      .     })     com.company.app.JSClass = JSClass; })();
  • 8. Create Object & Call a function // it need to include file JSClass.js in HTML, if it's // calling from HTML // create a object of the class varobj = new com.company.app.JSClass(); obj.moveBlock('0','-250','searchDiv');
  • 9. Inheritance Ext.ns("com.company.app");(function(){     varNewJSClass = Ext.extend(com.company.app.JSClass,{     .     .     .     })    com.company.app.NewJSClass = NewJSClass; })();
  • 10. Using extended class Ext.ns("com.company.app");(function(){     varNewJSClass = Ext.extend(com.company.app.JSClass ,{         color: 'blue',         constructor: function(config){            JSClass.superclass.constructor.apply(this, arguments)        },         // method override         moveBlock: function(newY, myDiv1){             Ext.get(myDiv1).moveTo(0, newY, true);         }     })    com.company.app.NewJSClass = NewJSClass; })();
  • 11. Module Pattern: POJO like class Ext.ns("com.company.app"); (function(){     var JSClass = Ext.extend(Object,{         //constructor function     constructor: function(config){         Ext.apply(this, config)     }     // class variable     ,value1: null     ,value2: null      // getter, setter     ,getValue1:function(){      return value1;     }    ,setValue1: function(val){      this.value1 = val;     }            })    com.company.app.JSClass = JSClass; })();
  • 12. Ext.apply simply copies data members from a source object to a destination object and allows you to provide default values Defaults are optional, when there is defaults it does this Run the next example in firebug, to understand it quickly Ext.apply() Syntax: Ext.apply(receivingObject, sendingObject, defaults) Ext.apply(receivingObject, defaults); Ext.apply(receivingObject, sendingObject);
  • 13. Continued.. var obj1 = {firstName: 'Rohan', lastName: 'Chandane'} console.log(obj1) //{firstName: 'Rohan', lastName: 'Chandane'} var obj2 = {job:'Dev', lang:'JavaScript', c: function(){}} console.log(obj2) // {job:'Dev', lang:'JavaScript' c: function(){}} var obj3 = Ext.apply(obj2, obj1, {newVar: 'new value'}) console.log(obj3) // {firstName: 'Rohan', lastName: 'Chandane', job:'Dev', lang:'JavaScript' c: function(){}, newVar: 'new value'} // replacing job value here var obj3 = Ext.apply(obj2, obj1, {job: 'new value'}) console.log(obj3) // {firstName: 'Rohan', lastName: 'Chandane', job:'new value', lang:'JavaScript' c: function(){}}
  • 14. Then what is the difference between Ext.apply() and Ext.extend() Ext.extend will inherit a superclass's data members and methods as well as add a superclass property and an override method. Ext.apply simply copies data members Continued..
  • 15. Modifying constructor in Module pattern to check Ext.apply() Adding console.log in JSClassto print config Create object of JSClassclass Continued.. constructor: function(config){ Ext.apply(this, config); console.log(this.newVar) } // creating object of JSClass (Module Pattern) var config = { varnewVar = “Rohan” } varnewObj = com.company.app.JSClass(config); // Rohan
  • 16. Extras of OO JavaScript
  • 17. JavaScript is dynamic object oriented language Properties and Function can be added and removed at run time Function can be moved from one object to another Example: Continued.. varobj = new Object();propertyName="firstName";propertyValue="Rohan"; console.log(obj.firstName);// undefinedeval("obj ."+propertyName+"='"+propertyValue+"'");console.log(obj.firstName);// Rohan delete (obj.firstName)console.log(obj.firstName)// undefined
  • 19. Ajax application can be divided in two part Ajax Deluxe Applications feel similar to a desktop app Its fully Ajax + JavaScript driven application Scalable and for big applications Ajax Lite Application/website feels more like a conventional web app Ajax is used for small operations like validation with server Useful only for small, quick functionality Web 2 App types
  • 20. Here, lets take a look at Ajax Deluxe first Continued..
  • 21. Project structure AppName | |_lib |   |_com |   |   |_company |   |       |_myapp |   |            |_package1 |   |                |_Main.js  |   |            |_package2 |   |_ext |       |_(Extracted ExtJS lib & folders) |       |_(...) ||_assets |   |_css |   |_img| |_Index.html
  • 22. Index.html Version 1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">     <title>Basic Setup</title>     <!-- Bring in the ExtJs Libraries and CSS -->     <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>     <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>     <script type="text/javascript" src="lib/ext/ext-all.js"></script>            <!-- Place the page specific js here -->        <script type="text/javascript">              Ext.onReady(function(){             // Mandatory: need to add this spacer             Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif';             // alert message box to check if ExtJS loaded             Ext.MessageBox.alert("Hello Example","Hello, Rohan! ExtJS loaded successfully!");         });      </script>          </head>     <body></body> </html>
  • 23. Index.html Version 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">     <title>Basic Setup</title>     <!-- Bring in the ExtJs Libraries and CSS -->     <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/>     <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>     <script type="text/javascript" src="lib/ext/ext-all.js"></script>            <!-- Place the page specific js here -->     <script type="text/javascript" src="lib/com/company/myapp/package1/Main.js "> </script>          </head>     <body></body> </html>
  • 24. Main.js  Version 2: Ext.onReady(function(){     // Mandatory: need to add this spacer /*[relative path to..]*/     Ext.BLANK_IMAGE_URL = ‘lib/ext/resources/images/default/s.gif';     Ext.QuickTips.init();     // alert message box to check if ExtJS loaded     Ext.MessageBox.alert("Hello Example","Hello, Rohan! ExtJS loaded successfully!"); });
  • 25. Now, for creating a Ajax Deluxe App from our existing setup It needs to use Border Layout (Viewport) We will edit Main.js and will add Ext.Viewport() As border layout has north, south, west, east & center region, We will add those using Ext.Panel() So Main.js will look like this - Continued..
  • 26. Main.js with Ext.Viewport() Ext.onReady(function(){ // Mandatory: need to add this spacer /*[relative path to..]*/ Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif'; Ext.QuickTips.init(); // viewport panels varnorthPanel = new Ext.Panel({ id: 'north-panel', height : 50,region: 'north', border: false, title:'Top Panel' }); varsouthPanel = new Ext.Panel({ id: 'south-panel', height : 200, region: 'south', title : 'South Panel', collapsible: true, collapsed: true }); varwestPanel = new Ext.Panel({ id: 'west-panel', layout: 'fit', width: 250, region: 'west', title: 'Navigation', collapsible: true }); varcenterPanel = new Ext.Panel({ region: 'center' ,layout: 'fit', title: 'Content Panel' }); // viewport new Ext.Viewport({ id: 'id-viewport' ,layout : 'border' ,items : [northPanel,southPanel,westPanel,centerPanel] }); });
  • 28. Here is object oriented programming with JavaScript We will create View, ViewLayout.js Class, which will render this Border Layout. We will modify Main.js and will create ViewLayout.js in directory package2 Add entry in Index.html for ViewLayout.js, Main.js OO
  • 29. Index.html <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Basic Setup</title> <!-- Bring in the ExtJs Libraries and CSS --> <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css"/> <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="lib/ext/ext-all.js"></script> <!-- Place the page specific js here --> <script type="text/javascript" src="lib/com/company/hello/package2/Main.js"></script> <script type="text/javascript" src="lib/com/company/hello/package2/ViewLayout.js"> </script> </head>
  • 30. ViewLayout.js Ext.ns("com.company.hello.package2"); (function(){ varViewLayout = Ext.extend(Object,{ constructor: function(config){ Ext.apply(this, config); }, // creating page layout, code goes here /* public */ createLayout: function(){ // viewport panels varnorthPanel = new Ext.Panel({ id: 'north-panel', height : 50,region: 'north', border: false, title:‘ Top Panel' }); varsouthPanel = new Ext.Panel({ id: 'south-panel', height : 200, region: 'south', title : 'South Panel', collapsible: true, collapsed: true }); varwestPanel = new Ext.Panel({ id: 'west-panel', layout: 'fit', width: 250, region: 'west', title: 'Navigation', collapsible: true }); varcenterPanel = new Ext.Panel({ region: 'center' ,layout: 'fit', title: 'Content Panel' }); code continues..
  • 31. Continued.. // viewport new Ext.Viewport({ id: 'id-viewport' ,layout : 'border' ,items : [northPanel, southPanel, westPanel, centerPanel] }); } }); com.company.hello.package2.ViewLayout = ViewLayout; })();
  • 32. Main.js Ext.onReady(function(){ // Mandatory: need to add this spacer /*[relative path to..]*/ Ext.BLANK_IMAGE_URL = 'lib/ext/resources/images/default/s.gif'; Ext.QuickTips.init(); // main execution start here, user defined function varonModuleLoad = function(){ varviewLayout = new com.company.hello.package2.ViewLayout(); viewLayout.createLayout(); } // main starting point onModuleLoad(); });
  • 33. Preview: using OO, ViewPort
  • 35. Singleton Ext.ns("com.netapp.hello.package1"); (function() { varSingletonModel = Ext.extend(Object, { _instance : null ,constructor : function() { console.log("Singleton constructor called : " + this.getInstance()); } ,getInstance : function() { if (this._instance === null) { this._instance = this.createInstance(); } return this._instance; } ,createInstance : function() { return 10; } }); com.netapp.hello.package1.SingletonModel = SingletonModel; })()
  • 36. Module Ext.ns("com.netapp.hello.package1"); (function(){ varModulePattern = Ext.extend(Object,{ name:"Rohan" ,constructor:function(){ console.log("constrcutor"); } ,getName:function(){ this.name; } ,setName:function(val){ this.name = val; } }); com.netapp.hello.package2.ModulePattern = ModulePattern; })()
  • 38. Use reusable code Object Oriented Approach Modularize code Do not access DOM frequently Its computational heavy code Use Lazy loading, wherever possible But avoid heavy nesting Use of event delegation Events should be assigned to a smaller subset of the document/element, rather than each individual element, this uses JavaScript’s event bubbling notion.  this approach takes less memory in browser Continued..
  • 39. Use of JavaScript minification, obfuscater YUI compressor, Linters  (jsonlint.com, jslint.com) Use of efficient programming practices in JavaScript Example: String manipulation - instead of string concatenation using ‘+’ operator, use of array’s .join() function, this way it will be better garbage collected. Cross Browser Scripting: using web standards, feature detection techniques instead browser detection technique and browser specific code Remove listeners which are not in use anymore Continued..
  • 40. Loops are heavy, it can be optimized by using simple techniquesIn for loop, whenever reading length of array, store it in some variable instead of reading it again and again using array.length Avoid creating lot of HTML code with JavaScript Continued..
  • 41. I will update these notes periodically with my experiments, stay tuned.. Note
  • 42. References http://www.jslog.com http://ajaxpatterns.org http://www.sencha.com/forum/ http://edspencer.net http://code.google.com/p/v8/ http://www.cherny.com/