SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
Building a
JavaScript Library
         John Resig (ejohn.org)
  jQuery JavaScript Library / Mozilla Corporation

       August 18th, 2007 - Google Tech Talk
jQuery
    Released Jan. 2006
✦

    Focus on DOM Traversal
✦

    Built in support for Events, Ajax, and
✦
    Animations
    Succinct code, small file size
✦

    Extensible via a plugin architecture
✦
jQuery Samples
    $(“#main div”).addClass(“test”);
✦


    $(“#main”).slideDown(“slow”);
✦


    $(“ul > li”).click(function(){
✦

        $(this).find(“ul”).toggle();
    });

    $(“#contents”).load(“doc.html”);
✦
Doing something right?
    ~25 people on the jQuery Team
✦

    1/4 million visitors per month
✦




    Fantastic Growth (via Google Trends)
✦
FUEL
    To be included in Firefox 3
✦

    A JavaScript library for extension
✦
    developers
    Provides helpers for: Browser tabs,
✦
    bookmarks, events, preferences
    Written in pure JavaScript, extensible
✦
FUEL Samples
    Application.prefs.all.forEach(function(p){
✦

      if ( p.modified )
        // do something
    });

    Application.events.addListener(“quit”, fn);
✦


    Application.browser
✦

        .open(quot;http://google.com/quot;).active = true;

    Application.bookmarks.all.forEach(function(cur){
✦

        if ( cur.url.match(/google.com/) )
            cur.remove();
    });
Need to know:
    Writing a Solid API
✦

    Implementation
✦

    Complex Applications
✦

    Browser Bugs
✦

    Documentation
✦

    Testing
✦

    Maintenance
✦
Writing A Solid API
Orthogonal
    Perform Universal Actions
✦

    CRUD your methods!
✦
    add/remove/delete/modify
    FUEL has the following on every object:
✦
    ✦ .all, .add(...), .remove(...), .get(...)

    jQuery was missing .removeAttr() for the
✦
    first couple months (oops!)
    Made a grid for FUEL, filled in the blanks
✦
Fear Adding Methods
    Methods can cause a support nightmare
✦

    Avoid adding, if you can
✦

    Defer to extensibility
✦

    jQuery:
✦
    ✦ Added .top(), .left(), .background()
    ✦ Duplicate of .css() - unnecessary
Embrace Removing Code
    Remove un-used code
✦

    Reduces the size of your API
✦

    Reduces your filesize
✦

    Make your code more maintainable
✦

    jQuery: Ran a poll to remove CSS 3
✦
    selectors.
    Reduced size of the API by 47% in 1.1
✦
Provide an Upgrade Path
    Expect compatibility changes
✦

    Provide transitional plugin
✦

    Plugin for jQuery 1.1, for jQuery 1.0 users
✦
    (+ documented in 3 languages)
Reduce to a common root
    Look for common patterns
✦

    Reduce to its core and build up
✦

    jQuery:
✦
    ✦ .eq(0), .gt(3), and .lt(2)
    ✦ why not just implement slice?
      .slice(0,1) or .slice(1,4)
Consistency
    Users can “expect” good naming
✦

    Pick a naming scheme and stick with it
✦
    ✦ .click() vs .onclick()

    Argument position
✦
    ✦ .method( options, arg2, ..., callback )

    Callback context
✦
    ✦ .method(function(){
          // this == DOMElement
      });
Implementation
Evolution of a JavaScript Coder

    “Everything is a reference!”
✦

    “You can do OO code!”
✦

    “Huh, so that’s how Object Prototypes
✦
    work!”
    “Thank God for closures!”
✦
Functional Programming
    Closures are essential
✦

    Understand this snippet:
✦
        (function(){
    ✦

          // your code...
        })();
        Great for ‘local variables’
    ✦

    Perfect for macros
✦
        var event = [‘click’,’focus’,’blur’,...];
    ✦

        jQuery.each(event,function(i,name){
            jQuery.prototype[name] = function(fn){
                return this.bind(name,fn);
            };
        });
Quick Tip: Local Vars
    (function(){
✦

      // your code...
      var test = false;

      this.method(function(){
        return test;
      });
    }).call(this);


    Locally-scoped variables
✦

    Access to instance
✦
Encapsulation
    Contain all of your code to a scope
✦

    Hide your code and prevent it from
✦
    leaking
    All of your code should be wrapped in a:
✦
        (function(){
    ✦

          // your code...
        })();


    BONUS! Your code compresses really well
✦
    with Dojo Compressor, et. al.
Namespacing
    Use as few global variables as feasible
✦

    One namespace is optimal
✦
    (see: Dojo, Yahoo UI, jQuery, MochiKit)
    Questions to ask:
✦
    ✦ Can my code coexist with other random
      code on the site?
    ✦ Can my code coexist with other copies
      of my own library?
    ✦ Can my code be embedded inside
      another namespace?
Don’t Extend Native Objects
    Down this path lies great pain and
✦
    suffering
    Impossible to get DOM extensions
✦
    working cross-browser
    Object.prototype kills kittens
✦

    JS 1.6 methods cause conflicts:
✦
    ✦ elem.getElementsByClassName
    ✦ array.forEach, .map, .filter
Perform Type Checking
    Make your API more fault resistant
✦

    Coerce values wherever possible
✦
    ✦ .css(Number) becomes:

        .css(Number + “px”)
                       becomes:
        .map(String)
    ✦

        .map(new Function(String))


    Error messages
✦
    ✦ Quite useful
    ✦ Byte-costly
    ✦ Solution: Move to ‘debugging’ extension
Quick Tip for OO
    Tweak your Object constructor
✦

    function jQuery(str, con){
✦

        if ( window == this )
            return new jQuery(str, con);
        // ...
    }


    Make it easier for users:
✦
    new jQuery(“#foo”) becomes:
    jQuery(“#foo”)
Quick Tip for Errors
    Never gobble errors
✦

    Ignore the templation to try{...}catch(e){}
✦

    Improves debug-ability for everyone
✦
Complex Applications
Extensibility
    Your code should be easily extensible
✦
    ✦ Methods: jQuery.fn.method = fn;
        $(...).method();
        Selectors: jQuery.expr[‘:’].foo
    ✦                                     = “...”;
        $(“:foo”)
        Animations: jQuery.easing.easeout
    ✦                                         = fn;
        .animate({height: 100}, “slow”, “easeout”);


    Write less, defer to others
✦

    Makes for cleaner code
✦

    Foster community and growth
✦
Pure OO Code
    Object-Oriented is only one answer
✦

    JavaScript != Java
✦

    Not a good solution
✦
    ✦ At least not until JavaScript 2
    ✦ Classes, Packages, etc.
Custom Events
    The answer lies in custom events
✦

    Dojo, jQuery, Yahoo UI - just added to
✦
    Prototype
    Components trigger events and listen for
✦
    others
    ✦ .bind(“drag”,fn)
    ✦ .trigger(“refresh”)
Browser Bugs
The Quirksmode Problem
    Fantastic resource
✦

    Tells you where problems are
✦

    Doesn’t tell you how to fix them
✦

    Need to focus on problem sets
✦
    ✦ Events
    ✦ Get Attribute
    ✦ Get Element Style
Solving a Problem
    Some issues are solved in depth
✦
    ✦ DOM Events
    ✦ DOM Traversal

    Many still require hard work:
✦
    ✦ getAttribute
    ✦ getComputedStyle

    Permute your test cases, look for edge
✦
    cases
When to run the fix
    Typical thought progression:
✦
    ✦ “I’ll just look at the useragent”
    ✦ “I’ll just detect to see if an object exists”
    ✦ “I’ll just think of an elegant solution to
      the problem”
    ✦ “I’ll just look at the useragent”
Documentation
Structured
    Provide a clear format
✦

    Users can build new views with it
✦
    ✦ No API view is perfect

    jQuery users built:
✦
    ✦ API browsers
    ✦ Cheat sheets
    ✦ Widgets
    ✦ Translations

    An API for your API!
✦
Users Want to Help
    Make barrier to helping very low
✦

    Answer: Keep your docs in a wiki
✦

    Only do this if you’ve already written all of
✦
    your docs
    ✦ Wiki != Documentation

    Use templates to maintain structure
✦
Focus on Leverage
    Write the docs that will get the most
✦
    benefit
    Rough Priority:
✦
    ✦ User-centric API
    ✦ Plugin authoring
    ✦ Docs on writing docs
    ✦ Advanced plugin authoring
Write the Docs Yourself
    It isn’t glamorous, but it’s essential
✦

    You must buckle-down and do it yourself
✦

    Improves your longevity and uptake
✦
Testing
1000% Essential
    Don’t trust any library that doesn’t have a
✦
    test suite
    ✦ Good: Prototype, MochiKit, jQuery,
      Yahoo UI
    Write your own suite (they’re pretty easy)
✦

    Be sure to handle async tests
✦
    ✦ Ajax
    ✦ Animations

    Pass in all supported browsers
✦
Test-Driven Development
    Write test cases before you tackle bugs
✦

    Find devs who love to write test cases
✦

    Check for failures before commit
✦

    Pure JS DOM (running in Rhino) can help
✦
    spot obvious errors
    ✦ pre_commit hook in SVN, if you can
      *cough* Google Code *cough*
Future of Testing
    Distributed Multi-Browser Testing
✦

    How it works:
✦
    ✦ Report results back to central server
    ✦ Server pushes new tests/code to clients
    ✦ Repeat

    jQuery and Prototype are very interested
✦
    in this (expect something soon)
    Test against browser nightlies
✦
    ✦ See: JS lib test cases in Mozilla trunk
Maintenance
Tackling New Bugs
    Create a rapid test environment
✦
    ✦ ./gen.sh bugnum (dom|ajax|selector|...)

    Your test suite must be passing
✦

    Have good coverage
✦

    Always test in all supported browsers to
✦
    avoid regressions
    Check unsupported browsers before
✦
    release
    ✦ Don’t want them to crash/error out
Use Your Community
    Use your community as a sounding board
✦
    ✦ Gauge the usefulness of features

    Users are great for finding weird edge cases
✦

    Pay attention to repeat questions
✦
    ✦ Indicative of problem in API design
    ✦ or lack of documentation
Maintain Focus
    Very, very, important
✦

    Users generally choose libraries for
✦
    ideological reasons
    Breaking your ideology will alienate your
✦
    users
    jQuery: Small, concise, code. Small
✦
    download, light core, easily extensible.
    Use plugins to divert functionality from
✦
    your core
More Details
    Contact Me:
✦
    jeresig@gmail.com
    More details:
✦
    ✦ http://ejohn.org/
    ✦ http://jquery.com/
    ✦ http://wiki.mozilla.org/FUEL
Fun
Fun With One Liners
    “I’m not suggesting that one-liners are the heart of all programming. But
✦
    they can be the hook to get someone exploring. A single line of code simply
    shows that a language can be focused. And it lets a beginner get
    comfortable with the basic atoms.” - _why

    jQuery allows for fantastic one liners
✦
One-Liners
    $(quot;div.sectionquot;)
✦


    $(quot;div.sectionquot;).removeClass(quot;sectionquot;).hide();
✦


     $(quot;div.sectionquot;)
✦

      .find(quot;dtquot;)
        .addClass(quot;sectionquot;)
        .click(function(){
           $(this).next().toggle();
        })
      .end()
      .find(quot;ddquot;)
      
 .hide()
      
 .filter(quot;:firstquot;)
      
    .show()
      
 .end()
      .end();
One-Liners
    Remove unsightly anonymous functions!
✦

    $(quot;div.sectionquot;)
✦

     .find(quot;dtquot;)
       .addClass(quot;sectionquot;)
       .onclick()
         .next().toggle().end()
       .end()
     .end()
     .find(quot;ddquot;)
     
 .hide()
     
 .filter(quot;:firstquot;)
     
   .show()
     
 .end()
     .end();
Domain-Specific Language
    $(quot;div.sectionquot;)
✦

      find(quot;dtquot;)
        addClass(quot;sectionquot;)
        click(
          next()
            toggle()
        )
      end()
      find(quot;ddquot;)
      
      hide()
      
 filter(quot;:firstquot;)
      
   show()
      
 end()
      end()
Domain-Specific Language
    $(quot;div.sectionquot;
✦

      find(quot;dtquot;
        addClass(quot;sectionquot;)
        click(
          next(
            toggle())))
      find(quot;ddquot;
      
      hide()
      
      filter(quot;:firstquot;
      
 show())))
Domain-Specific Language
    Lisp-y!
✦

    ($ quot;div.sectionquot;
✦

      (find quot;dtquot;
        (addClass quot;sectionquot;)
        (click (next (toggle))))
      (find quot;ddquot;
      
 (hide)
      
 (filter quot;:firstquot;
      
   (show)))))
Domain-Specific Language
    Python-y!
✦

    div.section:
✦

      dt:
        addClass quot;sectionquot;
        click
          next toggle
      dd:
      
 hide
      
 :first: show

    Give it a try:
✦
    http://ejohn.org/apps/jquery2/
    Secret Sauce:
✦
    <script type=”text/jquery”>...</script>

Más contenido relacionado

La actualidad más candente

Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5dynamis
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsJulien Lecomte
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010Nicholas Zakas
 
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Nicholas Zakas
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with SiestaGrgur Grisogono
 
Video.js - How to build and HTML5 Video Player
Video.js - How to build and HTML5 Video PlayerVideo.js - How to build and HTML5 Video Player
Video.js - How to build and HTML5 Video Playersteveheffernan
 
From Hacker to Programmer (w/ Webpack, Babel and React)
From Hacker to Programmer (w/ Webpack, Babel and React)From Hacker to Programmer (w/ Webpack, Babel and React)
From Hacker to Programmer (w/ Webpack, Babel and React)Joseph Chiang
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimizationStevie T
 
Making the HTML5 Video element interactive
Making the HTML5 Video element interactiveMaking the HTML5 Video element interactive
Making the HTML5 Video element interactiveCharles Hudson
 
Front end performance tip
Front end performance tipFront end performance tip
Front end performance tipSteve Yu
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Fwdays
 

La actualidad más candente (20)

Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
Progressive Enhancement 2.0 (jQuery Conference SF Bay Area 2011)
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
Unit and functional testing with Siesta
Unit and functional testing with SiestaUnit and functional testing with Siesta
Unit and functional testing with Siesta
 
Video.js - How to build and HTML5 Video Player
Video.js - How to build and HTML5 Video PlayerVideo.js - How to build and HTML5 Video Player
Video.js - How to build and HTML5 Video Player
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Front End Performance
Front End PerformanceFront End Performance
Front End Performance
 
From Hacker to Programmer (w/ Webpack, Babel and React)
From Hacker to Programmer (w/ Webpack, Babel and React)From Hacker to Programmer (w/ Webpack, Babel and React)
From Hacker to Programmer (w/ Webpack, Babel and React)
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimization
 
Making the HTML5 Video element interactive
Making the HTML5 Video element interactiveMaking the HTML5 Video element interactive
Making the HTML5 Video element interactive
 
Front end performance tip
Front end performance tipFront end performance tip
Front end performance tip
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
 

Destacado

The Technical Debt Trap - AgileIndy 2013
The Technical Debt Trap - AgileIndy 2013The Technical Debt Trap - AgileIndy 2013
The Technical Debt Trap - AgileIndy 2013Doc Norton
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.jsjeresig
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)jeresig
 
Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010jeresig
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Sagakaven yan
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainWeb Directions
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performancekaven yan
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
Khan Academy Computer Science
Khan Academy Computer ScienceKhan Academy Computer Science
Khan Academy Computer Sciencejeresig
 
Douglas Crockford - Ajax Security
Douglas Crockford - Ajax SecurityDouglas Crockford - Ajax Security
Douglas Crockford - Ajax SecurityWeb Directions
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockfordrajivmordani
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testingjeresig
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript ConceptsNaresh Kumar
 

Destacado (20)

The Technical Debt Trap - AgileIndy 2013
The Technical Debt Trap - AgileIndy 2013The Technical Debt Trap - AgileIndy 2013
The Technical Debt Trap - AgileIndy 2013
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)
 
Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Saga
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performance
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Khan Academy Computer Science
Khan Academy Computer ScienceKhan Academy Computer Science
Khan Academy Computer Science
 
Douglas Crockford - Ajax Security
Douglas Crockford - Ajax SecurityDouglas Crockford - Ajax Security
Douglas Crockford - Ajax Security
 
Json
JsonJson
Json
 
OOP in JavaScript
OOP in JavaScriptOOP in JavaScript
OOP in JavaScript
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockford
 
Understanding JavaScript Testing
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
 

Similar a Building JavaScript Libraries and APIs - Techniques for Success

Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MITjeresig
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In BrowsersGoogleTecTalks
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 
jQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjeresig
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureSimon Willison
 
The Future of Firefox and JavaScript
The Future of Firefox and JavaScriptThe Future of Firefox and JavaScript
The Future of Firefox and JavaScriptjeresig
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)jeresig
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jeresig
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesHenrik Olsson
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsGanesh Samarthyam
 
jQuery - Boston IxDA
jQuery - Boston IxDAjQuery - Boston IxDA
jQuery - Boston IxDAjeresig
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoojeresig
 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
 

Similar a Building JavaScript Libraries and APIs - Techniques for Success (20)

Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In Browsers
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
jQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UIjQuery 1.3 and jQuery UI
jQuery 1.3 and jQuery UI
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
 
The Future of Firefox and JavaScript
The Future of Firefox and JavaScriptThe Future of Firefox and JavaScript
The Future of Firefox and JavaScript
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss ToolsPresentations Unusual Java Bugs And Detecting Them Using Foss Tools
Presentations Unusual Java Bugs And Detecting Them Using Foss Tools
 
jQuery - Boston IxDA
jQuery - Boston IxDAjQuery - Boston IxDA
jQuery - Boston IxDA
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
The DOM is a Mess @ Yahoo
The DOM is a Mess @ YahooThe DOM is a Mess @ Yahoo
The DOM is a Mess @ Yahoo
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 

Más de jeresig

Does Coding Every Day Matter?
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?jeresig
 
Accidentally Becoming a Digital Librarian
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarianjeresig
 
2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)jeresig
 
Computer Vision as Art Historical Investigation
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigationjeresig
 
Hacking Art History
Hacking Art HistoryHacking Art History
Hacking Art Historyjeresig
 
Using JS to teach JS at Khan Academy
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academyjeresig
 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art Historyjeresig
 
NYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Resultsjeresig
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysisjeresig
 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art Historyjeresig
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)jeresig
 
jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jeresig
 
jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jeresig
 
jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jeresig
 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobilejeresig
 
jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jeresig
 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performancejeresig
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)jeresig
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)jeresig
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)jeresig
 

Más de jeresig (20)

Does Coding Every Day Matter?
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?
 
Accidentally Becoming a Digital Librarian
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarian
 
2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)
 
Computer Vision as Art Historical Investigation
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigation
 
Hacking Art History
Hacking Art HistoryHacking Art History
Hacking Art History
 
Using JS to teach JS at Khan Academy
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academy
 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
 
NYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Results
 
EmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
 
Applying Computer Vision to Art History
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
 
jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)
 
jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)
 
jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)
 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobile
 
jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)
 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performance
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
 

Último

IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024Matteo Carbone
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxMarkAnthonyAurellano
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Seta Wicaksana
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...ShrutiBose4
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
India Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportIndia Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportMintel Group
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 

Último (20)

Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCREnjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
Enjoy ➥8448380779▻ Call Girls In Sector 18 Noida Escorts Delhi NCR
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
No-1 Call Girls In Goa 93193 VIP 73153 Escort service In North Goa Panaji, Ca...
No-1 Call Girls In Goa 93193 VIP 73153 Escort service In North Goa Panaji, Ca...No-1 Call Girls In Goa 93193 VIP 73153 Escort service In North Goa Panaji, Ca...
No-1 Call Girls In Goa 93193 VIP 73153 Escort service In North Goa Panaji, Ca...
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 
India Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample ReportIndia Consumer 2024 Redacted Sample Report
India Consumer 2024 Redacted Sample Report
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 

Building JavaScript Libraries and APIs - Techniques for Success

  • 1. Building a JavaScript Library John Resig (ejohn.org) jQuery JavaScript Library / Mozilla Corporation August 18th, 2007 - Google Tech Talk
  • 2. jQuery Released Jan. 2006 ✦ Focus on DOM Traversal ✦ Built in support for Events, Ajax, and ✦ Animations Succinct code, small file size ✦ Extensible via a plugin architecture ✦
  • 3. jQuery Samples $(“#main div”).addClass(“test”); ✦ $(“#main”).slideDown(“slow”); ✦ $(“ul > li”).click(function(){ ✦ $(this).find(“ul”).toggle(); }); $(“#contents”).load(“doc.html”); ✦
  • 4. Doing something right? ~25 people on the jQuery Team ✦ 1/4 million visitors per month ✦ Fantastic Growth (via Google Trends) ✦
  • 5. FUEL To be included in Firefox 3 ✦ A JavaScript library for extension ✦ developers Provides helpers for: Browser tabs, ✦ bookmarks, events, preferences Written in pure JavaScript, extensible ✦
  • 6. FUEL Samples Application.prefs.all.forEach(function(p){ ✦ if ( p.modified ) // do something }); Application.events.addListener(“quit”, fn); ✦ Application.browser ✦ .open(quot;http://google.com/quot;).active = true; Application.bookmarks.all.forEach(function(cur){ ✦ if ( cur.url.match(/google.com/) ) cur.remove(); });
  • 7. Need to know: Writing a Solid API ✦ Implementation ✦ Complex Applications ✦ Browser Bugs ✦ Documentation ✦ Testing ✦ Maintenance ✦
  • 9. Orthogonal Perform Universal Actions ✦ CRUD your methods! ✦ add/remove/delete/modify FUEL has the following on every object: ✦ ✦ .all, .add(...), .remove(...), .get(...) jQuery was missing .removeAttr() for the ✦ first couple months (oops!) Made a grid for FUEL, filled in the blanks ✦
  • 10. Fear Adding Methods Methods can cause a support nightmare ✦ Avoid adding, if you can ✦ Defer to extensibility ✦ jQuery: ✦ ✦ Added .top(), .left(), .background() ✦ Duplicate of .css() - unnecessary
  • 11. Embrace Removing Code Remove un-used code ✦ Reduces the size of your API ✦ Reduces your filesize ✦ Make your code more maintainable ✦ jQuery: Ran a poll to remove CSS 3 ✦ selectors. Reduced size of the API by 47% in 1.1 ✦
  • 12. Provide an Upgrade Path Expect compatibility changes ✦ Provide transitional plugin ✦ Plugin for jQuery 1.1, for jQuery 1.0 users ✦ (+ documented in 3 languages)
  • 13. Reduce to a common root Look for common patterns ✦ Reduce to its core and build up ✦ jQuery: ✦ ✦ .eq(0), .gt(3), and .lt(2) ✦ why not just implement slice? .slice(0,1) or .slice(1,4)
  • 14. Consistency Users can “expect” good naming ✦ Pick a naming scheme and stick with it ✦ ✦ .click() vs .onclick() Argument position ✦ ✦ .method( options, arg2, ..., callback ) Callback context ✦ ✦ .method(function(){ // this == DOMElement });
  • 16. Evolution of a JavaScript Coder “Everything is a reference!” ✦ “You can do OO code!” ✦ “Huh, so that’s how Object Prototypes ✦ work!” “Thank God for closures!” ✦
  • 17. Functional Programming Closures are essential ✦ Understand this snippet: ✦ (function(){ ✦ // your code... })(); Great for ‘local variables’ ✦ Perfect for macros ✦ var event = [‘click’,’focus’,’blur’,...]; ✦ jQuery.each(event,function(i,name){ jQuery.prototype[name] = function(fn){ return this.bind(name,fn); }; });
  • 18. Quick Tip: Local Vars (function(){ ✦ // your code... var test = false; this.method(function(){ return test; }); }).call(this); Locally-scoped variables ✦ Access to instance ✦
  • 19. Encapsulation Contain all of your code to a scope ✦ Hide your code and prevent it from ✦ leaking All of your code should be wrapped in a: ✦ (function(){ ✦ // your code... })(); BONUS! Your code compresses really well ✦ with Dojo Compressor, et. al.
  • 20. Namespacing Use as few global variables as feasible ✦ One namespace is optimal ✦ (see: Dojo, Yahoo UI, jQuery, MochiKit) Questions to ask: ✦ ✦ Can my code coexist with other random code on the site? ✦ Can my code coexist with other copies of my own library? ✦ Can my code be embedded inside another namespace?
  • 21. Don’t Extend Native Objects Down this path lies great pain and ✦ suffering Impossible to get DOM extensions ✦ working cross-browser Object.prototype kills kittens ✦ JS 1.6 methods cause conflicts: ✦ ✦ elem.getElementsByClassName ✦ array.forEach, .map, .filter
  • 22. Perform Type Checking Make your API more fault resistant ✦ Coerce values wherever possible ✦ ✦ .css(Number) becomes: .css(Number + “px”) becomes: .map(String) ✦ .map(new Function(String)) Error messages ✦ ✦ Quite useful ✦ Byte-costly ✦ Solution: Move to ‘debugging’ extension
  • 23. Quick Tip for OO Tweak your Object constructor ✦ function jQuery(str, con){ ✦ if ( window == this ) return new jQuery(str, con); // ... } Make it easier for users: ✦ new jQuery(“#foo”) becomes: jQuery(“#foo”)
  • 24. Quick Tip for Errors Never gobble errors ✦ Ignore the templation to try{...}catch(e){} ✦ Improves debug-ability for everyone ✦
  • 26. Extensibility Your code should be easily extensible ✦ ✦ Methods: jQuery.fn.method = fn; $(...).method(); Selectors: jQuery.expr[‘:’].foo ✦ = “...”; $(“:foo”) Animations: jQuery.easing.easeout ✦ = fn; .animate({height: 100}, “slow”, “easeout”); Write less, defer to others ✦ Makes for cleaner code ✦ Foster community and growth ✦
  • 27. Pure OO Code Object-Oriented is only one answer ✦ JavaScript != Java ✦ Not a good solution ✦ ✦ At least not until JavaScript 2 ✦ Classes, Packages, etc.
  • 28. Custom Events The answer lies in custom events ✦ Dojo, jQuery, Yahoo UI - just added to ✦ Prototype Components trigger events and listen for ✦ others ✦ .bind(“drag”,fn) ✦ .trigger(“refresh”)
  • 30. The Quirksmode Problem Fantastic resource ✦ Tells you where problems are ✦ Doesn’t tell you how to fix them ✦ Need to focus on problem sets ✦ ✦ Events ✦ Get Attribute ✦ Get Element Style
  • 31. Solving a Problem Some issues are solved in depth ✦ ✦ DOM Events ✦ DOM Traversal Many still require hard work: ✦ ✦ getAttribute ✦ getComputedStyle Permute your test cases, look for edge ✦ cases
  • 32. When to run the fix Typical thought progression: ✦ ✦ “I’ll just look at the useragent” ✦ “I’ll just detect to see if an object exists” ✦ “I’ll just think of an elegant solution to the problem” ✦ “I’ll just look at the useragent”
  • 34. Structured Provide a clear format ✦ Users can build new views with it ✦ ✦ No API view is perfect jQuery users built: ✦ ✦ API browsers ✦ Cheat sheets ✦ Widgets ✦ Translations An API for your API! ✦
  • 35. Users Want to Help Make barrier to helping very low ✦ Answer: Keep your docs in a wiki ✦ Only do this if you’ve already written all of ✦ your docs ✦ Wiki != Documentation Use templates to maintain structure ✦
  • 36. Focus on Leverage Write the docs that will get the most ✦ benefit Rough Priority: ✦ ✦ User-centric API ✦ Plugin authoring ✦ Docs on writing docs ✦ Advanced plugin authoring
  • 37. Write the Docs Yourself It isn’t glamorous, but it’s essential ✦ You must buckle-down and do it yourself ✦ Improves your longevity and uptake ✦
  • 39. 1000% Essential Don’t trust any library that doesn’t have a ✦ test suite ✦ Good: Prototype, MochiKit, jQuery, Yahoo UI Write your own suite (they’re pretty easy) ✦ Be sure to handle async tests ✦ ✦ Ajax ✦ Animations Pass in all supported browsers ✦
  • 40. Test-Driven Development Write test cases before you tackle bugs ✦ Find devs who love to write test cases ✦ Check for failures before commit ✦ Pure JS DOM (running in Rhino) can help ✦ spot obvious errors ✦ pre_commit hook in SVN, if you can *cough* Google Code *cough*
  • 41. Future of Testing Distributed Multi-Browser Testing ✦ How it works: ✦ ✦ Report results back to central server ✦ Server pushes new tests/code to clients ✦ Repeat jQuery and Prototype are very interested ✦ in this (expect something soon) Test against browser nightlies ✦ ✦ See: JS lib test cases in Mozilla trunk
  • 43. Tackling New Bugs Create a rapid test environment ✦ ✦ ./gen.sh bugnum (dom|ajax|selector|...) Your test suite must be passing ✦ Have good coverage ✦ Always test in all supported browsers to ✦ avoid regressions Check unsupported browsers before ✦ release ✦ Don’t want them to crash/error out
  • 44. Use Your Community Use your community as a sounding board ✦ ✦ Gauge the usefulness of features Users are great for finding weird edge cases ✦ Pay attention to repeat questions ✦ ✦ Indicative of problem in API design ✦ or lack of documentation
  • 45. Maintain Focus Very, very, important ✦ Users generally choose libraries for ✦ ideological reasons Breaking your ideology will alienate your ✦ users jQuery: Small, concise, code. Small ✦ download, light core, easily extensible. Use plugins to divert functionality from ✦ your core
  • 46. More Details Contact Me: ✦ jeresig@gmail.com More details: ✦ ✦ http://ejohn.org/ ✦ http://jquery.com/ ✦ http://wiki.mozilla.org/FUEL
  • 47. Fun
  • 48. Fun With One Liners “I’m not suggesting that one-liners are the heart of all programming. But ✦ they can be the hook to get someone exploring. A single line of code simply shows that a language can be focused. And it lets a beginner get comfortable with the basic atoms.” - _why jQuery allows for fantastic one liners ✦
  • 49. One-Liners $(quot;div.sectionquot;) ✦ $(quot;div.sectionquot;).removeClass(quot;sectionquot;).hide(); ✦ $(quot;div.sectionquot;) ✦ .find(quot;dtquot;) .addClass(quot;sectionquot;) .click(function(){ $(this).next().toggle(); }) .end() .find(quot;ddquot;) .hide() .filter(quot;:firstquot;) .show() .end() .end();
  • 50. One-Liners Remove unsightly anonymous functions! ✦ $(quot;div.sectionquot;) ✦ .find(quot;dtquot;) .addClass(quot;sectionquot;) .onclick() .next().toggle().end() .end() .end() .find(quot;ddquot;) .hide() .filter(quot;:firstquot;) .show() .end() .end();
  • 51. Domain-Specific Language $(quot;div.sectionquot;) ✦ find(quot;dtquot;) addClass(quot;sectionquot;) click( next() toggle() ) end() find(quot;ddquot;) hide() filter(quot;:firstquot;) show() end() end()
  • 52. Domain-Specific Language $(quot;div.sectionquot; ✦ find(quot;dtquot; addClass(quot;sectionquot;) click( next( toggle()))) find(quot;ddquot; hide() filter(quot;:firstquot; show())))
  • 53. Domain-Specific Language Lisp-y! ✦ ($ quot;div.sectionquot; ✦ (find quot;dtquot; (addClass quot;sectionquot;) (click (next (toggle)))) (find quot;ddquot; (hide) (filter quot;:firstquot; (show)))))
  • 54. Domain-Specific Language Python-y! ✦ div.section: ✦ dt: addClass quot;sectionquot; click next toggle dd: hide :first: show Give it a try: ✦ http://ejohn.org/apps/jquery2/ Secret Sauce: ✦ <script type=”text/jquery”>...</script>