SlideShare une entreprise Scribd logo
1  sur  29
Twitter Meta:
                               @kvangork
                                   #OOJS




Object-Oriented Javascript
order from chaos (we hope)
function bfIsAlphaNumeric( cfield )
{

    cfield.value = TRIM2(cfield.value);

    for ( i = 0 ; i < cfield.value.length ; i++)

    {

    
 var n = cfield.value.substr(i,1);

    
 if ( n != 'a' && n != 'b' && n != 'c' && n != 'd'

    
 
 && n != 'e' && n != 'f' && n != 'g' && n != 'h'

    
 
 //...

    
 
 && n != '8' && n != '9'

    
 
 && n != '_' && n != '@' && n != '-' && n != '.' )

    
 {

    
 
 window.alert("Only Alphanumeric are allowed.nPlease re-enter the value.");

    
 
 cfield.value = '';

    
 
 cfield.focus();

    
 }

    
 cfield.value = cfield.value.toUpperCase();

    }

    return;
}
everything is an

Object
even functions




            http://www.flickr.com/photos/sanchtv/4192677571
every

Object
has a

Prototype


            http://www.flickr.com/photos/macwalsh/4403701509
Tools


//Helper function. Copy all properties of props into obj
function mixin (obj, props) {
  if(obj && props && typeof props == 'object') {
     for(var property in props) {
        obj[property] = props[property];
     }
  }
}
Tools


//Pseudo-Classical Extension Function
//Preserves: inheritance
//        superclass
function extend (superclass, overrides) {
   //...complicated, dragon-filled, etc...
   //get the well-commented code from http://gist.github.com/339766

    //Returns new class, descended from superclass, with overrides applied.
}
Basic Container Class

var Container = function(){

   this.items = []; //empty array to hold items
};

Container.prototype.addItem = function(item) {

   this.items.push(item);
}

Container.prototype.getCount = function() {

   return this.items.length;
}
var Container = function(){

   this.items = []; //empty array to hold items
};
Container.prototype.addItem = function(item) {

   this.items.push(item);
}
Container.prototype.getCount = function() {

   return this.items.length;
}

var   LimitedContainer = extend(Container, {

     constructor: function(maxItems) {

     
 LimitedContainer.superclass.constructor.call(this);

     
 this.maxItems = maxItems;

     },


     addItem: function(item) {

     
 if(this.getCount() < this.maxItems) {

     
 
 LimitedContainer.superclass.addItem.call(this, item);

     
 }

     }
});
var Container = function(){

   this.items = []; //empty array to hold items
};
Container.prototype.addItem = function(item) {

   this.items.push(item);
}
Container.prototype.getCount = function() {

   return this.items.length;
}

var   LimitedContainer = extend(Container, {

     constructor: function(maxItems) {

     
 LimitedContainer.superclass.constructor.call(this);

     
 this.maxItems = maxItems;

     },


     addItem: function(item) {

     
 if(this.getCount() < this.maxItems) {

     
 
 LimitedContainer.superclass.addItem.call(this, item);

     
 }

     }
});
http://www.flickr.com/photos/thomasroche/2481517741
Bearded Men of the 21st Century (1939)
Config Objects


function LimitedContainer (maxItems) {
  this.maxItems = maxItems;
}


new LimitedContainer(3);
Config Objects


    function LimitedContainer(config) {

    mixin(this, config); //who knows what you'll need

    this.maxItems = config.maxItems || 3;
}


new LimitedContainer({maxItems: 3});
Model   View
Example
Example




          View
Example




    Model   View
var DS = {};

//Empty constructor, this is just a stub
DS.QueryControllerView = extend(Object, {

   //No constructor required, use Object's default


   //Required Delegate methods:

   QueryCompleted: function (resultSet) {

   
 alert("Your query finished with " + resultSet.features.length + " features returned.");

   },


      QueryFailed: function (error) {

      
 alert("Sorry, your query failed. Here are its last words: " + error);

      }
});
DS.QueryController = extend(Object, {


    constructor: function (config) {

    
 //copy all config parameters

    
 mixin(this, config);


    
 //verify required parameter presence and types

    
 if (!(this.view instanceof DS.QueryControllerView)) throw("Incorrect view...");

    
 if (!this.serviceURL) throw("Missing Service URL.");


    
 this.queryTask = new esri.tasks.QueryTask(this.serviceURL);

    },


    initiateQuery: function (geometry) {

    
 if (!geometry instanceof esri.geometry.Geometry) throw("Invalid geometry parameter...");


    
 var query = new esri.tasks.Query();

    
 query.geometry = geometry;

    
 query.returnGeometry = true;


    
 this.runningQuery = this.queryTask.execute(query, this.callback, this.errback);

    },
view = new DS.QueryControllerView();

controller = new DS.QueryController({

   view: view,

   serviceURL: "http://sampleserver1.arcg...mographics/ESRI_Census_USA/MapServer/3"
});

//set up click event handler
dojo.connect(map, "onClick", function(evt) {

   controller.initiateQuery(evt.mapPoint);
});
Demo
DS.QueryControllerMapView = extend(DS.QueryControllerView, {

      constructor: function(config) {

      
 mixin(this, config);

      

      
 if (!(this.map instanceof esri.Map)) throw("Incorrect map parameter...");

      

      },


      QueryCompleted: function(resultSet) {

      
 if(resultSet.features.length) {

      
 
 this.map.graphics.clear();

      
 

      
 
 var mySymbol = new esri.symbol.SimpleFillSymbol(...255,0,0.25]));

      
 
 var feature = resultSet.features[0];

      
 

      
 
 feature.setSymbol(mySymbol);

      
 

      
 
 this.map.graphics.add(feature);

      
 }

      }

});
view = new DS.QueryControllerMapView({map: map});

controller = new DS.QueryController({

   view: view,

   serviceURL: "http://sampleserver1.arcg...mographics/ESRI_Census_USA/MapServer/3"
});

//set up click event handler
dojo.connect(map, "onClick", function(evt) {

   controller.initiateQuery(evt.mapPoint);
});
Demo
Resources

Object-Oriented Javascript by Stoyan Stefanov
YUI Theater, especially Douglas Crockford’s videos
Read Library Source Code - Dojo, jQuery, YUI
Download this deck and code at http://prng.vangorkom.org
You should follow me on Twitter: @kvangork

Contenu connexe

Tendances

_Function Builders in Swift #love_swift
_Function Builders in Swift #love_swift_Function Builders in Swift #love_swift
_Function Builders in Swift #love_swiftTomohiro Kumagai
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2Pat Cavit
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
AST Rewriting Using recast and esprima
AST Rewriting Using recast and esprimaAST Rewriting Using recast and esprima
AST Rewriting Using recast and esprimaStephen Vance
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga beginsDaniel Franz
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCTomohiro Kumagai
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript名辰 洪
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6m0bz
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive ShellGiovanni Lodi
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile ProcessEyal Vardi
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesRainer Stropek
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0Eyal Vardi
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Ignacio Martín
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲームNoritada Shimizu
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS RoutingEyal Vardi
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creatorsGeorge Bukhanov
 

Tendances (20)

_Function Builders in Swift #love_swift
_Function Builders in Swift #love_swift_Function Builders in Swift #love_swift
_Function Builders in Swift #love_swift
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
AST Rewriting Using recast and esprima
AST Rewriting Using recast and esprimaAST Rewriting Using recast and esprima
AST Rewriting Using recast and esprima
 
The redux saga begins
The redux saga beginsThe redux saga begins
The redux saga begins
 
Swift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDCSwift で JavaScript 始めませんか? #iOSDC
Swift で JavaScript 始めませんか? #iOSDC
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive Shell
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
AngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile ServicesAngularJS with TypeScript and Windows Azure Mobile Services
AngularJS with TypeScript and Windows Azure Mobile Services
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 

En vedette

Migrations PHP 5 - Solutions linux 2009
Migrations PHP 5 - Solutions linux 2009Migrations PHP 5 - Solutions linux 2009
Migrations PHP 5 - Solutions linux 2009Eric D.
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extensionNguyen Duc Phu
 
Geek Austin PHP Class - Session 2
Geek Austin PHP Class - Session 2Geek Austin PHP Class - Session 2
Geek Austin PHP Class - Session 2jimbojsb
 
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012Sunny U Okoro
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server Sunny U Okoro
 
Tableau Reports and Oracle OBIEE
Tableau Reports and  Oracle OBIEETableau Reports and  Oracle OBIEE
Tableau Reports and Oracle OBIEESunny U Okoro
 

En vedette (7)

Migrations PHP 5 - Solutions linux 2009
Migrations PHP 5 - Solutions linux 2009Migrations PHP 5 - Solutions linux 2009
Migrations PHP 5 - Solutions linux 2009
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extension
 
Geek Austin PHP Class - Session 2
Geek Austin PHP Class - Session 2Geek Austin PHP Class - Session 2
Geek Austin PHP Class - Session 2
 
Learning java
Learning javaLearning java
Learning java
 
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
MiS SharePoint 2010-SSRS, Power View & PowerPivot 2012
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server
 
Tableau Reports and Oracle OBIEE
Tableau Reports and  Oracle OBIEETableau Reports and  Oracle OBIEE
Tableau Reports and Oracle OBIEE
 

Similaire à Object-Oriented Javascript

Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScriptAndrew Dupont
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the mastersAra Pehlivanian
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)Anders Jönsson
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013Laurent_VB
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax BasicsRichard Paul
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Engineering JavaScript
Engineering JavaScriptEngineering JavaScript
Engineering JavaScriptJim Purbrick
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 

Similaire à Object-Oriented Javascript (20)

ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Engineering JavaScript
Engineering JavaScriptEngineering JavaScript
Engineering JavaScript
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Object-Oriented Javascript

  • 1. Twitter Meta: @kvangork #OOJS Object-Oriented Javascript order from chaos (we hope)
  • 2. function bfIsAlphaNumeric( cfield ) { cfield.value = TRIM2(cfield.value); for ( i = 0 ; i < cfield.value.length ; i++) { var n = cfield.value.substr(i,1); if ( n != 'a' && n != 'b' && n != 'c' && n != 'd' && n != 'e' && n != 'f' && n != 'g' && n != 'h' //... && n != '8' && n != '9' && n != '_' && n != '@' && n != '-' && n != '.' ) { window.alert("Only Alphanumeric are allowed.nPlease re-enter the value."); cfield.value = ''; cfield.focus(); } cfield.value = cfield.value.toUpperCase(); } return; }
  • 3.
  • 4.
  • 5.
  • 6. everything is an Object even functions http://www.flickr.com/photos/sanchtv/4192677571
  • 7. every Object has a Prototype http://www.flickr.com/photos/macwalsh/4403701509
  • 8. Tools //Helper function. Copy all properties of props into obj function mixin (obj, props) { if(obj && props && typeof props == 'object') { for(var property in props) { obj[property] = props[property]; } } }
  • 9. Tools //Pseudo-Classical Extension Function //Preserves: inheritance // superclass function extend (superclass, overrides) { //...complicated, dragon-filled, etc... //get the well-commented code from http://gist.github.com/339766 //Returns new class, descended from superclass, with overrides applied. }
  • 10.
  • 11. Basic Container Class var Container = function(){ this.items = []; //empty array to hold items }; Container.prototype.addItem = function(item) { this.items.push(item); } Container.prototype.getCount = function() { return this.items.length; }
  • 12. var Container = function(){ this.items = []; //empty array to hold items }; Container.prototype.addItem = function(item) { this.items.push(item); } Container.prototype.getCount = function() { return this.items.length; } var LimitedContainer = extend(Container, { constructor: function(maxItems) { LimitedContainer.superclass.constructor.call(this); this.maxItems = maxItems; }, addItem: function(item) { if(this.getCount() < this.maxItems) { LimitedContainer.superclass.addItem.call(this, item); } } });
  • 13. var Container = function(){ this.items = []; //empty array to hold items }; Container.prototype.addItem = function(item) { this.items.push(item); } Container.prototype.getCount = function() { return this.items.length; } var LimitedContainer = extend(Container, { constructor: function(maxItems) { LimitedContainer.superclass.constructor.call(this); this.maxItems = maxItems; }, addItem: function(item) { if(this.getCount() < this.maxItems) { LimitedContainer.superclass.addItem.call(this, item); } } });
  • 15. Bearded Men of the 21st Century (1939)
  • 16. Config Objects function LimitedContainer (maxItems) { this.maxItems = maxItems; } new LimitedContainer(3);
  • 17. Config Objects function LimitedContainer(config) { mixin(this, config); //who knows what you'll need this.maxItems = config.maxItems || 3; } new LimitedContainer({maxItems: 3});
  • 18. Model View
  • 20. Example View
  • 21. Example Model View
  • 22. var DS = {}; //Empty constructor, this is just a stub DS.QueryControllerView = extend(Object, { //No constructor required, use Object's default //Required Delegate methods: QueryCompleted: function (resultSet) { alert("Your query finished with " + resultSet.features.length + " features returned."); }, QueryFailed: function (error) { alert("Sorry, your query failed. Here are its last words: " + error); } });
  • 23. DS.QueryController = extend(Object, { constructor: function (config) { //copy all config parameters mixin(this, config); //verify required parameter presence and types if (!(this.view instanceof DS.QueryControllerView)) throw("Incorrect view..."); if (!this.serviceURL) throw("Missing Service URL."); this.queryTask = new esri.tasks.QueryTask(this.serviceURL); }, initiateQuery: function (geometry) { if (!geometry instanceof esri.geometry.Geometry) throw("Invalid geometry parameter..."); var query = new esri.tasks.Query(); query.geometry = geometry; query.returnGeometry = true; this.runningQuery = this.queryTask.execute(query, this.callback, this.errback); },
  • 24. view = new DS.QueryControllerView(); controller = new DS.QueryController({ view: view, serviceURL: "http://sampleserver1.arcg...mographics/ESRI_Census_USA/MapServer/3" }); //set up click event handler dojo.connect(map, "onClick", function(evt) { controller.initiateQuery(evt.mapPoint); });
  • 25. Demo
  • 26. DS.QueryControllerMapView = extend(DS.QueryControllerView, { constructor: function(config) { mixin(this, config); if (!(this.map instanceof esri.Map)) throw("Incorrect map parameter..."); }, QueryCompleted: function(resultSet) { if(resultSet.features.length) { this.map.graphics.clear(); var mySymbol = new esri.symbol.SimpleFillSymbol(...255,0,0.25])); var feature = resultSet.features[0]; feature.setSymbol(mySymbol); this.map.graphics.add(feature); } } });
  • 27. view = new DS.QueryControllerMapView({map: map}); controller = new DS.QueryController({ view: view, serviceURL: "http://sampleserver1.arcg...mographics/ESRI_Census_USA/MapServer/3" }); //set up click event handler dojo.connect(map, "onClick", function(evt) { controller.initiateQuery(evt.mapPoint); });
  • 28. Demo
  • 29. Resources Object-Oriented Javascript by Stoyan Stefanov YUI Theater, especially Douglas Crockford’s videos Read Library Source Code - Dojo, jQuery, YUI Download this deck and code at http://prng.vangorkom.org You should follow me on Twitter: @kvangork

Notes de l'éditeur

  1. Model = RESTful data source on server. View = HTML Template Engine in JS, or UI Widgets. Use DI with controller. View should be an abstract class (like an interface) which will throw errors if you fail to implement required members. Controller = Javascript class, takes in View class in constructor, along with any model configuration params.
  2. Strap in, it&amp;#x2019;s time for CODE
  3. Strap in, it&amp;#x2019;s time for CODE