SlideShare a Scribd company logo
{   Evented...
Why You
Shouldn’t Write
  OO jQuery
Why You
Shouldn’t Write
  OO jQuery
        Troll
Organization
Organization

    X
Code Reuse
We’re Used to It
Strategy
Widget
Widget
Widget
Widget
function function function
Widget


AjaxWidget
Widget


   AjaxWidget


HistoryAjaxWidget
Widget


   AjaxWidget
                    super


HistoryAjaxWidget
Widget
                super


   AjaxWidget
                        super


HistoryAjaxWidget
Why You Shouldn't Write OO
Widget


AjaxWidget
Widget         Widget


AjaxWidget   HistoryWidget
Composability
X
Composability
OO Code in JS
 is Crippled
Evented Code
Instead of
 calling a
 method
{
widget.activate();
User Code




 Widget
User Code

1:1

 Widget
User Code

1:1   Sync

 Widget
Trigger an
   Event
}
element.trigger("activate")
User Code




Listener    Listener   Listener
Advantages
Familiar Model
{
$("div").click(function() {

})
   // do stuff
Evented Code
  Fits More
 Cleanly with
Requirements
“When the user
 picks an item
   from the
autocompleter”
Real Example
Caveat: Simple
  Technique
I’ve Used This
Technique on
Large Projects
Tabs
Why You Shouldn't Write OO
div.ui-tabs
click       keypress


    div.ui-tabs
click       keypress


    div.ui-tabs


   tabactivate
click       keypress


    div.ui-tabs


   tabactivate
click       keypress


    div.ui-tabs


   tabactivate
a) open pane
      b) mark tab selected

           tabactivate


             default

analogy: typing in text box
triggers a change event
a) open pane
b) mark tab selected
      tabactivate

     return false

       default
Tech in the
 Example
Arista Theme
Sass and
Compass
(try to avoid
using JS to set
  up layouts)
Staticmatic
jQuery BBQ
(Ben Alman)
Demo

More Related Content

KEY
Sprout core and performance
PDF
Hack tutorial
PDF
jQuery secrets
PDF
React.js触ってみた 吉澤和香奈
PDF
Introducing jQuery
PPT
Backbone.js
PDF
jQuery and Rails, Sitting in a Tree
PPTX
Sprout core and performance
Hack tutorial
jQuery secrets
React.js触ってみた 吉澤和香奈
Introducing jQuery
Backbone.js
jQuery and Rails, Sitting in a Tree

What's hot (20)

PPTX
jQuery Presentation
PDF
jQuery in 15 minutes
PDF
Magento2&java script (2)
PDF
PPTX
How to increase Performance of Web Application using JQuery
PPTX
AngularJS Compile Process
PPTX
jQuery
PPTX
AngulrJS Overview
PPTX
AngularJS Services
PDF
Backbone.js — Introduction to client-side JavaScript MVC
PDF
What the FUF?
PDF
J querypractice
PPTX
AngularJS - $http & $resource Services
PPTX
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
PPTX
JavaScript and jQuery Basics
PPTX
jQuery basics for Beginners
PPTX
AngularJS $Provide Service
PDF
Jqeury ajax plugins
PDF
jQuery Loves Developers - Oredev 2009
jQuery Presentation
jQuery in 15 minutes
Magento2&java script (2)
How to increase Performance of Web Application using JQuery
AngularJS Compile Process
jQuery
AngulrJS Overview
AngularJS Services
Backbone.js — Introduction to client-side JavaScript MVC
What the FUF?
J querypractice
AngularJS - $http & $resource Services
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
JavaScript and jQuery Basics
jQuery basics for Beginners
AngularJS $Provide Service
Jqeury ajax plugins
jQuery Loves Developers - Oredev 2009
Ad

Viewers also liked (6)

PDF
Testing Merb
PDF
Appnovation One Sheet
PDF
Merb Day Keynote
PDF
Vaporware To Awesome
PDF
Merb jQuery
PDF
Making your oss project more like rails
Testing Merb
Appnovation One Sheet
Merb Day Keynote
Vaporware To Awesome
Merb jQuery
Making your oss project more like rails
Ad

Similar to Why You Shouldn't Write OO (20)

DOCX
TY.BSc.IT Java QB U1
PPTX
Windows Store app using XAML and C#: Enterprise Product Development
PPTX
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
PPT
BOF-5110 Extending the Groovy SwingBuilder
PDF
Workshop: Building Vaadin add-ons
PPTX
jQuery Ecosystem
PDF
Dojo1.0_Tutorials
PDF
Dojo1.0_Tutorials
PPTX
Lab #2: Introduction to Javascript
PPT
Using And Extending The DotNetNuke Widget Framework
PPT
Google Web Toolkits
PPTX
Dynamic Actions, the Hard Parts
PPT
Extending Groovys Swing User Interface in Builder to Build Richer Applications
PDF
Vaadin 7 CN
PDF
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
PDF
Salesforce Lightning Tips & Tricks
PDF
Google Web Toolkit
PPT
GWT MVP Case Study
PDF
Awt event
PDF
Ajax-Tutorial
TY.BSc.IT Java QB U1
Windows Store app using XAML and C#: Enterprise Product Development
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
BOF-5110 Extending the Groovy SwingBuilder
Workshop: Building Vaadin add-ons
jQuery Ecosystem
Dojo1.0_Tutorials
Dojo1.0_Tutorials
Lab #2: Introduction to Javascript
Using And Extending The DotNetNuke Widget Framework
Google Web Toolkits
Dynamic Actions, the Hard Parts
Extending Groovys Swing User Interface in Builder to Build Richer Applications
Vaadin 7 CN
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Salesforce Lightning Tips & Tricks
Google Web Toolkit
GWT MVP Case Study
Awt event
Ajax-Tutorial

More from Yehuda Katz (10)

PDF
Writing Fast Client-Side Code: Lessons Learned from SproutCore
PDF
SproutCore: Amber
PDF
Rails 3: Dashing to the Finish
PDF
Organizing jQuery Projects Without OO
PDF
Rails 3 overview
PDF
Merb Camp Keynote
PDF
PDF
DataMapper
PDF
jQuery and Ruby Web Frameworks
PDF
jQuery Presentation to Rails Developers
Writing Fast Client-Side Code: Lessons Learned from SproutCore
SproutCore: Amber
Rails 3: Dashing to the Finish
Organizing jQuery Projects Without OO
Rails 3 overview
Merb Camp Keynote
DataMapper
jQuery and Ruby Web Frameworks
jQuery Presentation to Rails Developers

Why You Shouldn't Write OO