SlideShare a Scribd company logo
Fork JS improvements
       November 17th, 2011
Summary
Summary
‣   General code cleanup
Summary
‣   General code cleanup
‣   Variables
Summary
‣   General code cleanup
‣   Variables
‣   Event binding
Summary
‣   General code cleanup
‣   Variables
‣   Event binding
‣   jQuery 1.7
General code cleanup
General code cleanup




Old
      if(!jsFrontend) { var jsFrontend = new Object(); }

      jsFrontend =
      {
          // init something like a constructor
          init: function()
          {
              // call functions
          },



          // end
          eoo: true;
      }



      $(document).ready(jsFrontend.init);
General code cleanup




New
      var jsFrontend =
      {
          // init something like a constructor
          init: function()
          {
              // call functions
          }
      }



      $(jsFrontend.init);
General code cleanup




Example
General code cleanup




Style :(
General code cleanup




Style :)
Variables
Variables




Scope
Variables




Scope
Scope is determined by where a variable is declared, and in
some cases whether the var keyword is used.
Variables




Scope: global
Variables




Scope: global
Can be referenced anywhere in the document but must be:
Variables




Scope: global
Can be referenced anywhere in the document but must be:
‣  Declared outside a function, with or without the var
   keyword
Variables




Scope: global
Can be referenced anywhere in the document but must be:
‣  Declared outside a function, with or without the var
   keyword
‣  Declared inside a function, without the var keyword, but
   only once the function is called
Variables




Scope: local
Variables




Scope: local
Can only be referenced within the function it is declared but
must be:
Variables




Scope: local
Can only be referenced within the function it is declared but
must be:
‣  Declared inside a function, with the var keyword
Variables




Why use variables?
For speed and maintenance
Variables




Example 1
      var value = 5; // gobal since we're in the global scope, outside any function

      jsFrontend.faq.feedback =
      {
          init: function()
          {
              // variables
              var number = 3; // local (we're already inside this anonymous function)
              result = 100; // global once this function is called

              var $header = $('#header'); // local (we're already inside this anonymous function)
              $navigation = $('#navigation'); // global once this function is called

              // bind click event
              $header.on('click', function()
              {
                  var color = 'blue'; // local
                  endResult = 'green'; // global once this function is called

                    var $body = $('body'); // local
                    $frame = $('#frame'); // global once this function is called

                    number++; //   this variable is declared outside of this function's scope,
                              //   so changes will affect not only this function's scope,
                              //   but the declaring function's scope
                              //   which means that this variable is "re-used" every time
              });
          }
      }
Variables




Example 2
Event binding
Event binding




Old
Event binding




New
jQuery 1.7
jQuery 1.7




Changes
http://blog.jquery.com/2011/11/03/jquery-1-7-released/
jQuery 1.7




Changes
‣   New event API .on() and .off() used for bind, live and
    delegate
jQuery 1.7




Bind
jQuery 1.7




Bind
jQuery 1.7




Live
jQuery 1.7




Live
jQuery 1.7




Delegate
jQuery 1.7




Delegate
jQuery 1.7




Changes
‣   New event API: .on() and .off() used for bind, live and
    delegate
‣   Better HTML5 support (footer, header, section, ...)
jQuery 1.7




Changes
‣   New event API: .on() and .off() used for bind, live and
    delegate
‣   Better HTML5 support (footer, header, section, ...)
‣   event.layerX and event.layerY
jQuery 1.7




Changes
‣   New event API: .on() and .off() used for bind, live and
    delegate
‣   Better HTML5 support (footer, header, section, ...)
‣   event.layerX and event.layerY
‣   $.isNaN() replaced with $.isNumeric()
jQuery 1.7




Changes
‣   New event API: .on() and .off() used for bind, live and
    delegate
‣   Better HTML5 support (footer, header, section, ...)
‣   event.layerX and event.layerY
‣   $.isNaN() replaced with $.isNumeric()
‣   $.event.proxy() use $.proxy() instead
Questions?
twitter.com/decthomas
thomas@fork-cms.com
  www.fork-cms.com

More Related Content

PDF
Protocol-Oriented MVVM
PPTX
Java Script Promise
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
Practical Protocols with Associated Types
PDF
Getting Comfortable with JS Promises
PDF
Protocol-Oriented MVVM (extended edition)
PPTX
JavaScript Promises
PDF
Intro to Asynchronous Javascript
Protocol-Oriented MVVM
Java Script Promise
Asynchronous JavaScript Programming with Callbacks & Promises
Practical Protocols with Associated Types
Getting Comfortable with JS Promises
Protocol-Oriented MVVM (extended edition)
JavaScript Promises
Intro to Asynchronous Javascript

What's hot (18)

PDF
Practical JavaScript Promises
PDF
Angular Performance: Then, Now and the Future. Todd Motto
PDF
Excellent
PDF
Angular promises and http
PDF
JavaScript Promises
PDF
Angular server-side communication
PPTX
Javascript this keyword
PDF
Rails is not just Ruby
PDF
Protocol in Swift
PDF
Protocol-Oriented Programming in Swift
PPTX
JavaScript Conditional Statements
PDF
Utilizing Bluebird Promises
PDF
Protocols promised-land-2
PPTX
Microservices workshop
PDF
iOSクリーンアーキテクチャのデータ戦略公開用
PPT
You promise?
ODP
Angular JS Unit Testing - Overview
Practical JavaScript Promises
Angular Performance: Then, Now and the Future. Todd Motto
Excellent
Angular promises and http
JavaScript Promises
Angular server-side communication
Javascript this keyword
Rails is not just Ruby
Protocol in Swift
Protocol-Oriented Programming in Swift
JavaScript Conditional Statements
Utilizing Bluebird Promises
Protocols promised-land-2
Microservices workshop
iOSクリーンアーキテクチャのデータ戦略公開用
You promise?
Angular JS Unit Testing - Overview
Ad

Similar to Fork 3.0 JS improvements (20)

PDF
JavaScript: Patterns, Part 1
PDF
KEY
The JavaScript Programming Primer
PDF
LISA QooxdooTutorial Slides
PDF
DrupalCon jQuery
PPT
PDF
Javascript: the important bits
PPTX
UNIT 1 (7).pptx
PDF
Lecture 03 - JQuery.pdf
KEY
JavaScript Neednt Hurt - JavaBin talk
KEY
User Interface Development with jQuery
PDF
Closures in Javascript
PDF
Introduction to Jquery
PDF
J query fundamentals
PDF
JavaScript: Patterns, Part 3
PPTX
Javascript And J Query
PPTX
Awesomeness of JavaScript…almost
PDF
JavaScript Functions
PDF
fuser interface-development-using-jquery
PDF
JavaScript Primer
JavaScript: Patterns, Part 1
The JavaScript Programming Primer
LISA QooxdooTutorial Slides
DrupalCon jQuery
Javascript: the important bits
UNIT 1 (7).pptx
Lecture 03 - JQuery.pdf
JavaScript Neednt Hurt - JavaBin talk
User Interface Development with jQuery
Closures in Javascript
Introduction to Jquery
J query fundamentals
JavaScript: Patterns, Part 3
Javascript And J Query
Awesomeness of JavaScript…almost
JavaScript Functions
fuser interface-development-using-jquery
JavaScript Primer
Ad

Recently uploaded (20)

PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PDF
IFRS Notes in your pocket for study all the time
PDF
MSPs in 10 Words - Created by US MSP Network
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
Laughter Yoga Basic Learning Workshop Manual
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
DOCX
Business Management - unit 1 and 2
PDF
A Brief Introduction About Julia Allison
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
DOCX
Euro SEO Services 1st 3 General Updates.docx
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PDF
Types of control:Qualitative vs Quantitative
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PPTX
Probability Distribution, binomial distribution, poisson distribution
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
IFRS Notes in your pocket for study all the time
MSPs in 10 Words - Created by US MSP Network
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Laughter Yoga Basic Learning Workshop Manual
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
Business Management - unit 1 and 2
A Brief Introduction About Julia Allison
340036916-American-Literature-Literary-Period-Overview.ppt
Euro SEO Services 1st 3 General Updates.docx
New Microsoft PowerPoint Presentation - Copy.pptx
Types of control:Qualitative vs Quantitative
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Lecture (1)-Introduction.pptx business communication
Power and position in leadershipDOC-20250808-WA0011..pdf
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Principles of Marketing, Industrial, Consumers,
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
Probability Distribution, binomial distribution, poisson distribution

Fork 3.0 JS improvements