Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =

Slides:



Advertisements
Similar presentations
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Advertisements

The Web Warrior Guide to Web Design Technologies
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
ITEC200 – Week03 Inheritance and Class Hierarchies.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Advanced Object-Oriented Programming Features
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
ASP.NET Programming with C# and SQL Server First Edition
ExtJS Classes By Aaron Conran. Creating Classes Creating classes in JavaScript is easy as creating a constructor function and using the new keyword when.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
® IBM Software Group © 2006 IBM Corporation Creating JSF/EGL Template Pages This section describes how to create.JTPL (Java Template Pages) using the Page.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
ZFApp Preview Walkthrough. What is ZFApp? ZFApp is an application framework built on top of Zend Framework Fully compatible with the latest ZF Versions.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
PRESENTED BY, P.S.S.SWAMY..  What is an application package.  What is an application class.  Object oriented concepts.  Understanding application.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
JavaScript, Fourth Edition
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Getting a handle on ActionScript A basic primer for non-programmers.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Introduction to OOP in VB.NET using Robots ACSE Conference, Nov 2004 Michael Devoy Monsignor Doyle C.S.S., Cambridge
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
Introduction to Object-Oriented Programming Lesson 2.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Changing HTML Attributes each() function Anonymous Functions $(this) keyword.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Object Oriented JavaScript. JavaScript Really only 4 types in JavaScript – number, string, boolean – Object (includes arrays) Remember that an object.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
Advance ExtJS concepts. Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x =
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Object-Oriented Programming: Classes and Objects.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
12 Data abstraction Packages and encapsulation
Using Procedures and Exception Handling
CS240: Advanced Programming Concepts
Lecture 22 Inheritance Richard Gesick.
WEB PROGRAMMING JavaScript.
Java – Inheritance.
Using Templates and Library Items
3.2 Working with Data Scope of variables 29/07/2019.
Presentation transcript:

Advance ExtJS concepts

Javascript Object var obj = {}; obj.x = 10; obj.y = 20; var obj = new Object; obj.x = 10; obj.y = 20; function Foo() {this.x = 10; this.y = 20;} var obj = new Foo In JavaScript, each Object can inherit properties from another object, called it's prototype function Bar() {this.z = 20;} Bar.prototype = new Foo var obj = new Bar x10 y20 Foo.prototype constructorFoo Object.protoype constructorObject

Creating Classes Creating classes in JavaScript is easy as creating a constructor function and using the new keyword when creating an instance of that class. Person Class: var Person = function(config) { Ext.apply(this, config); }; Using the Person class: var me = new Person({ fName: ‘Sachin’, lName: ‘Mittal’, dob: ’xx/xx/xxxx’ });

Ext.apply Ext.apply copies all attributes of one object to another. Ext.apply is often used at the beginning of constructors to copy configuration arguments to the this scope. The new keyword creates a new blank object in the scope of this. You can also supply a 3 rd argument as a default configuration. Ex: Ext.apply(this, config); // with defaults var defConfig = {test: ‘abc’}; Ext.apply(this, config, defConfig);

Ext.applyIf Ext.applyIf works similarly to Ext.apply except if properties already exist they won’t be overwritten. Ex: var point = point || {}; var default = {x: 0, y: 0}; Ext.applyIf(point, default);

Inheritance Ext provides a utility function called Ext.extend that is the mechanism for implementing class inheritance using the Ext framework. It gives you the ability to modify or extend the base functionality of any JavaScript class without making code changes directly to the class itself. It is the preferred method for extending Ext components. MyClass = Ext.extend(Ext.SomeClass, { someFunction : function(arg1, arg2){ // custom code // call base class MyClass.superclass.someFunction.call(this, arg1, arg2); // custom code } );

Ext.extend Ext.extend is used to extend or inherit from classes which already exist. Generic Pattern: var SubClass = function() { SubClass.superclass.constructor.call(this); }; Ext.extend(SubClass, BaseClass, { newMethod : function() {}, overriddenMethod : function() {} }; SubClass extends BaseClass and overrides overridenMethod and adds newMethod.

How to create custom extjs components Sometimes you will have a component whose config options you want to make reusable. For example, you may have a set of panels with the same width and height, only the title is different. This is called a preconfigured class. Another reason you want to use OO classes is that you want to extend the functionality of another class. Let us say you want to add a function in the above panel and override an existing function.

Constructor Model // MyPanel Extends Ext.Panel MyPanel = Ext.extend(Ext.Panel, { // constructor function constructor: function(config) { Ext.apply(this, { // Put your pre-configured config options here width: 300, height: 300 }); MyPanel.superclass.constructor.apply(this, arguments); } }); var myfirstpanel = new MyPanel({ title: 'My First Panel' });

Factory Pattern function createMyPanel(config) { return new Ext.Panel(Ext.apply({ //Pre-configured config options go here width: 300, height: 300 }, config)); }; var myfirstpanel = createMyPanel({ title: 'My First Panel' });

Extending Functionality // Constructor var MyPanel = function(config) { //Reusable config options here Ext.apply(this, { width: 300, height: 300 }); // And Call the superclass to preserve baseclass functionality MyPanel.superclass.constructor.apply(this, arguments); // Here you can add functionality that requires the object to exist, like event handling. this.on('click', function() {alert("You Clicked " + this.title);}, this); };

Another way to write the constructor above var MyPanel = function(config) { // Call the superclass to preserve baseclass functionality MyPanel.superclass.constructor.call(this, Ext.apply({ //Reusable config options here width: 300, height: 300 }, config)); // After superclass constructor add functionality that requires // the object to exist (like event handling...listeners) this.on('click', function() {alert("You Clicked " + this.title);}, this); };

// MyPanel Extends Ext.Panel Ext.extend(MyPanel, Ext.Panel, { // Here you can add static variables for the class. variables that will have // the same value for all object instances of this class. // New function added myNewFunction: function() { }, // Override an existing function onRender: function() { MyPanel.superclass.onRender.apply(this, arguments); this.myNewFunction(); } }); // register xtype to allow for lazy initialization Ext.reg('mypanelxtype', MyPanel );

initComponent (new) To extend an Ext class we do not need to create a constructor function. We just need to assign the return value of Ext.extend call to a variable in our name space. Ext.extend takes the original class and a config object as arguments and returns our extension. All tasks that were done in a custom constructor function are now done in initComponent function that we almost always override. initComponent is called early from the parent constructor function. However, initComponent of the original class contains useful code that needs to be executed. Registering an xtype for your extension is not mandatory but it is very good practice.

initComponent: function() { //Reusable config options here Ext.apply(this, { width: 300, height: 300 }); // And Call the superclass to preserve baseclass functionality MyPanel.superclass.initComponent.apply(this, arguments); // Here you can add functionality that requires the object to // exist, like event handling. this.on('click',function() {alert("You Clicked " + this.title);},this); }

var MyPanel = Ext.extend(Ext.Panel, { // Here you can add static variables for the class. variables that // will have the same value for all object instances of this class. initComponent: function() { … }, // New function added myNewFunction: function() { }, // Override an existing function onRender: function() { MyPanel.superclass.onRender.apply(this, arguments); this.myNewFunction(); } }); var myfirstpanel = new MyPanel({ title: 'My First Panel' });

Composition or Extension When creating a new class, the decision must be made whether to own an instance of a utility class which is to perform a major role, or to extend that class. It is recommended that you extend the nearest base class to the functionality required.

The Template method Pattern The render method is called (This is done by a Container’s layout manager). This method may not be overridden and is implemented by the Ext base class

The Template Methods for Component onRender afterRender onAdded onRemoved onShow onHide onDisable onEnable onDestroy

Which class to extend Component If the required UI control does not need to contain any other controls, that is, if it just to encapsulate some form of HTML which performs the requirements BoxComponent I needs to have its size and/or position managed by a layout manager Container If the required UI control is to contain other UI elements, but does not need any additional capabilities of Panel – onBeforeAdd – onAdd – onRemove – onLayout Panel If the required UI control must have a header, footer, or toolbars, then Ext.Panel is the appropriate class to extend. – onCollapse – onExpand

When a subclass is not needed Method injection When in one particular situation, one piece of functionality of an existing class needs to be overridden, or added to, an instance-specific implementation. Configuring a Plugin A Plugin is a class which implements an init(Component) method which is attached to a Component through the plugins config option. A Factory method If all that is required is a specific configuration of an existing class. Override a functionality (universally) Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name. Usage: Ext.override(MyClass, { newMethod1: function(){ // etc. }, newMethod2: function(foo){ // etc. } });

Namespaces It is typical to include many libraries, widgets and snippets of code from many different sources. not a safe assumption that you have the entire global namespace at your disposal. When developing your own scripts you should place all of your classes and singletons into namespaces to avoid collisions with other developers code. An abstract container to hold all of your classes and singletons

Namespaces (ExtJS) if (!App) App = {}; if (!App.form) App.form = {}; if (!App.data) App.data = {}; Ext provides the Ext.namespace method which will setup namespaces for you, including checking if the namespace already exists. /* Ext.namespace will create these objects if they don't already exist */ Ext.namespace('App', 'App.form', 'App.data'); /* Now you can define a new class such as SampleForm inside of the App.form package */ App.form.SampleForm = Ext.extend(Ext.form.FormPanel, { initComponent: function() {... App.form.SampleForm.superclass.initComponent.call(this); } }); /* Define MySingleton inside of the App.data package */ App.data.MySingleton = function() { return { x: 4 }; }();

Upgrade of ExtJS (to version 3.2) Look for extended classes and see if they override any base ExtJS Classe's methods. Ensure that these are not modified. Ensure you have updated all the Ext-provided CSS with the new CSS from version 3. Ensure you have updated all the Ext-provided images with the new images from version 3. Read the release notes and look for areas in coding using changed functionality. They have done some changes in data stores and ajax. If you have not extended these classes then you should be OK.

Debugging ExtJS Using IE Explorer debugger for 8.x Using MS Visual studio Using Firebug for firefox Using other in-built debuggers with respective browsers

ExtJS Performance Build your own Extjs - this will just use the componenets you need, and as well css. Reduces file size. Compress using JSmin. Concatenate all your Javascript sources into one file for live running. Serve javascript files gzipped. Avoid memory leaks like using mon instead of on to bind events

ExtJS Cross browser ExtJs supports – IE 7.x, 8.x – FF 2.x, 3.x – Webkit based browsers (safari, chrome) Handling of trailing commas in JSON for IE CSS issues related to box model on IE Other CSS issues like float, z-index

ExtJS Coding Standards The unit of indentation is four spaces Avoid lines longer than 80 characters. Place the break after an operator, ideally after a comma. Be generous with comments. All variables should be declared before used. All functions should be declared before they are used. Inner functions should follow the var statement. Names should be formed from the 26 upper and lower case letters (A.. Z, a.. z), the 10 digits (0.. 9), and _ (underbar). Global variables should be in all caps.

Each line should contain at most one statement. Put a ; (semicolon) at the end of every simple statement. A return statement with a value should not use ( ) (parentheses) around the value. Use {} instead of new Object(). Use [] instead of new Array(). Avoid the use of the comma operator except for very disciplined use in the control part of for statements. It is almost always better to use the === and !== operators. The == and != operators do type coercion. The eval function is the most misused feature of JavaScript. Avoid it.