SlideShare a Scribd company logo
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

More Related Content

What's hot

_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
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 
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
 
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
 

What's hot (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
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
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
 
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
 

Viewers also liked

Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Jeffrey Way - IT Professional
Jeffrey Way - IT ProfessionalJeffrey Way - IT Professional
Jeffrey Way - IT ProfessionalJeffWay
 
(Best) Practices for the Solo Developer
(Best) Practices for the Solo Developer(Best) Practices for the Solo Developer
(Best) Practices for the Solo DeveloperMichael Eaton
 
Integrating Apple Macs Using Novell Technologies
Integrating Apple Macs Using Novell TechnologiesIntegrating Apple Macs Using Novell Technologies
Integrating Apple Macs Using Novell TechnologiesNovell
 
A Force of One - Agile and the Solo Developer
A Force of One - Agile and the Solo DeveloperA Force of One - Agile and the Solo Developer
A Force of One - Agile and the Solo DeveloperClint Edmonson
 
Confessions of Joe Developer
Confessions of Joe DeveloperConfessions of Joe Developer
Confessions of Joe DeveloperDaniel Greenfeld
 
Building a Service-driven Enterprise Cloud
Building a Service-driven Enterprise CloudBuilding a Service-driven Enterprise Cloud
Building a Service-driven Enterprise CloudNovell
 
Securing Your Endpoints Using Novell ZENworks Endpoint Security Management
Securing Your Endpoints Using Novell ZENworks Endpoint Security ManagementSecuring Your Endpoints Using Novell ZENworks Endpoint Security Management
Securing Your Endpoints Using Novell ZENworks Endpoint Security ManagementNovell
 
Practical Machine Learning: Innovations in Recommendation Workshop
Practical Machine Learning:  Innovations in Recommendation WorkshopPractical Machine Learning:  Innovations in Recommendation Workshop
Practical Machine Learning: Innovations in Recommendation WorkshopMapR Technologies
 
What's New with Linux on System z
What's New with Linux on System zWhat's New with Linux on System z
What's New with Linux on System zNovell
 
Practical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookPractical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookWei-Yuan Chang
 

Viewers also liked (12)

Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Jeffrey Way - IT Professional
Jeffrey Way - IT ProfessionalJeffrey Way - IT Professional
Jeffrey Way - IT Professional
 
(Best) Practices for the Solo Developer
(Best) Practices for the Solo Developer(Best) Practices for the Solo Developer
(Best) Practices for the Solo Developer
 
Integrating Apple Macs Using Novell Technologies
Integrating Apple Macs Using Novell TechnologiesIntegrating Apple Macs Using Novell Technologies
Integrating Apple Macs Using Novell Technologies
 
A Force of One - Agile and the Solo Developer
A Force of One - Agile and the Solo DeveloperA Force of One - Agile and the Solo Developer
A Force of One - Agile and the Solo Developer
 
Confessions of Joe Developer
Confessions of Joe DeveloperConfessions of Joe Developer
Confessions of Joe Developer
 
Paris Data Geeks
Paris Data GeeksParis Data Geeks
Paris Data Geeks
 
Building a Service-driven Enterprise Cloud
Building a Service-driven Enterprise CloudBuilding a Service-driven Enterprise Cloud
Building a Service-driven Enterprise Cloud
 
Securing Your Endpoints Using Novell ZENworks Endpoint Security Management
Securing Your Endpoints Using Novell ZENworks Endpoint Security ManagementSecuring Your Endpoints Using Novell ZENworks Endpoint Security Management
Securing Your Endpoints Using Novell ZENworks Endpoint Security Management
 
Practical Machine Learning: Innovations in Recommendation Workshop
Practical Machine Learning:  Innovations in Recommendation WorkshopPractical Machine Learning:  Innovations in Recommendation Workshop
Practical Machine Learning: Innovations in Recommendation Workshop
 
What's New with Linux on System z
What's New with Linux on System zWhat's New with Linux on System z
What's New with Linux on System z
 
Practical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookPractical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at Facebook
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 

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

Editor's Notes

  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