SlideShare ist ein Scribd-Unternehmen logo
1 von 77
Downloaden Sie, um offline zu lesen
Enterprise JavaScript
                            Session 3 - History and the Rest




Wednesday, November 7, 12
Hi, I’m Troy




Wednesday, November 7, 12
Hi, I’m Troy
                   • Developing software Since 1979
                   • Initially Game Software in Assembly (6502
                            and x86)
                   • Currently JavaScript, C#, Java, Objective-C
                   • rockncoder@gmail.com


Wednesday, November 7, 12
jssaturday.com
                            Nov. 10th, Long Beach Convention
                                          Center
                             Discount code: RiaConsultingLLC
                                        Save $65!!!



Wednesday, November 7, 12
Today’s Agenda




Wednesday, November 7, 12
Today’s Agenda
                   • Somethings We Missed




Wednesday, November 7, 12
Today’s Agenda
                   • Somethings We Missed
                   • The History Object




Wednesday, November 7, 12
Today’s Agenda
                   • Somethings We Missed
                   • The History Object
                   • jQuery Mobile




Wednesday, November 7, 12
Today’s Agenda
                   • Somethings We Missed
                   • The History Object
                   • jQuery Mobile
                   • Backbone.js



Wednesday, November 7, 12
Somethings We Missed

                   • Typeof
                   • Functions
                   • Exceptions




Wednesday, November 7, 12
typeof
                   • The typeof operator detects the type of an
                            object
                   • It evaluates to a string which represents the
                            object’s type
                   • Unfortunately it is broken


Wednesday, November 7, 12
typeof
                      var msg = “hello there”;
                      var bob = typeof msg;
                      console.log(“msg is of type” + bob);
                      /* prints - msg is of type string */




Wednesday, November 7, 12
Type        typeof

                             Object     “object”
                             Array      “object”
                            Function   “function”
                             String     “string”
                            Number     “number”
                            Boolean    “boolean”
                              null      “object”
                            undefined   “undefined”

Wednesday, November 7, 12
typeof demo



Wednesday, November 7, 12
Function Properties
                   • The “this” parameter
                   • The arguments parameter
                   • call & apply methods
                   • length property



Wednesday, November 7, 12
The “this” parameter
                   • Functions receive two hidden parameters
                   • The first hidden parameter is this
                   • It holds the context of the object which
                            called the function
                   • When called from global space, this points
                            to the window object
                   • Can modify the calling object via this
Wednesday, November 7, 12
The arguments parameter

                   • The second hidden parameter is arguments
                   • It contains a list of all the parameter passed
                            to the function
                   • arguments is array-like, values in it can be
                            index, but no other array methods




Wednesday, November 7, 12
arguments demo



Wednesday, November 7, 12
call & apply methods
                   • The call & apply methods both allow you to
                            pass the this object to a function
                   • The difference is in how you pass
                            parameters to the function
                   • call: parameters sent individually
                   • apply: parameters sent in an array

Wednesday, November 7, 12
call & apply methods
                                demo


Wednesday, November 7, 12
The length property
                   • The length property holds the number
                            parameters the function was declared with




Wednesday, November 7, 12
length property demo



Wednesday, November 7, 12
Hands-on Exercise




Wednesday, November 7, 12
Hands-on Exercise
                   • Use arguments to create a function,
                            calcSum, which returns the sum of an
                            unknown number of numbers passed to it




Wednesday, November 7, 12
Hands-on Exercise
                   • Use arguments to create a function,
                            calcSum, which returns the sum of an
                            unknown number of numbers passed to it
                   • The following should all work:
                            calcSum(1,2,3);
                            calcSum(4,5,6,7,8);
                            calcSum(100,200,450,74);



Wednesday, November 7, 12
Hands-on Exercise, pt. 2




Wednesday, November 7, 12
Hands-on Exercise, pt. 2
                   • Make the calcSum function more robust by
                            filtering non-numbers out of the summing
                            function




Wednesday, November 7, 12
Hands-on Exercise, pt. 2
                   • Make the calcSum function more robust by
                            filtering non-numbers out of the summing
                            function
                   • The following should all work:
                            calcSum(1,2, true,3);
                            calcSum(4,5,”bob”,6,7,8);
                            calcSum(100,200,calcSum,450,74);



Wednesday, November 7, 12
Exceptions
                   • Like other languages JavaScript has
                            exceptions
                   • The exceptions can also be thrown using
                            the throw statement:
                            if(typeof a !== ‘number’ || typeof b !== ‘number’){
                              throw {
                                 name: ‘TypeError’,
                                 message: ‘add needs numbers‘
                              };
                            }




Wednesday, November 7, 12
Exceptions
                      function calcBob () {
                        try {
                          /* operation which might generate
                              an exception */
                        } catch(e) {
                            /* handle exception */
                        }
                      }




Wednesday, November 7, 12
The History Object



Wednesday, November 7, 12
The History Problem
                   • Modern JavaScript web apps have three
                            problems with regards to history:
                   • They aren’t navigate-able by web crawlers
                   • They don’t have bookmark-able URLs
                   • They don’t behave correctly


Wednesday, November 7, 12
history problem demo



Wednesday, November 7, 12
The History Object
                   • The History Object is part of the window
                            object
                   • The API is very small, three methods and
                            one property
                   • methods: back(), forward(), go()
                   • Properties: length

Wednesday, November 7, 12
The History Object
                   • The History object can only move forward
                            or backwards to places the user has already
                            been
                   • Not able to add items to history
                   • Not very useful


Wednesday, November 7, 12
HTML5 History
                   • pushState()
                   • replaceState()
                   • popstate event
                   • history.state



Wednesday, November 7, 12
pushState()
                   • pushState(state, title, URL);
                   • state - a JS object associated with the new
                            history entry
                   • title - currently ignored by browser
                   • URL - the new history entry’s URL


Wednesday, November 7, 12
replaceState()
                   • replaceState(state, title, URL);
                   • Behaves exactly like pushState except it
                            modifies the current history entry instead
                            of creating a new one




Wednesday, November 7, 12
popstate event
                   • A popstate event is fired by the browser
                            every time the active history entry changes




Wednesday, November 7, 12
history.state
                   • var currentState = history.state;
                   • Allows you to read the current state of the
                            history object




Wednesday, November 7, 12
History polyfills
                   • HTML5 pushState is supported on most
                            modern browsers
                   • Older browsers will need to use a polyfill
                            like History.js




Wednesday, November 7, 12
history object demo



Wednesday, November 7, 12
https://github.com/
                balupton/history.js/wiki/
               Intelligent-State-Handling


Wednesday, November 7, 12
jQuery Mobile



Wednesday, November 7, 12
Quick Intro to jQuery
                          Mobile
              A unified, HTML5-based user interface system
              for all popular mobile device platforms, built on
              the rock-solid jQuery and jQuery UI
              foundation. Its lightweight code is built with
              progressive enhancement, and has a flexible,
              easily theme-able design.




Wednesday, November 7, 12
Demo #1



Wednesday, November 7, 12
Page Structure
                   • Header
                   • Footer
                   • Content Area




Wednesday, November 7, 12
Header
                   • Page Title
                   • Left Button
                   • Right Button




Wednesday, November 7, 12
Footer
                   • Title
                   • Buttons




Wednesday, November 7, 12
Content Area
                            This is where your stuff goes.




Wednesday, November 7, 12
How It Works
                   • Dynamic DOM Manipulation
                   • HTML5 Pseudo-Attributes
                   • There is no free lunch




Wednesday, November 7, 12
Dynamic DOM
                            Manipulation demo


Wednesday, November 7, 12
HTML5 Pseudo-
                                 Attributes
                   • JQM Uses Pseudo-Attributes (data-)
                   • Standard Browser Behavior - Ignore
                            Unknown Attributes
                   • Allows for Some Functionality on low-end
                            browsers




Wednesday, November 7, 12
Form Elements
                             (aka widgets)
                   • buttons
                   • sliders
                   • radio buttons
                   • checkboxes
                   • select menus
                   • etc.

Wednesday, November 7, 12
Lists
                   • Basic Lists
                   • Nested Lists
                   • List Dividers
                   • Split Lists
                   • etc.


Wednesday, November 7, 12
Multi-Page Apps
                   • basic setup
                   • transitions
                   • passing data between pages




Wednesday, November 7, 12
Events



Wednesday, November 7, 12
Touch
                   • tap
                   • taphold
                   • swipe
                   • swipeleft
                   • swiperight


Wednesday, November 7, 12
Page
                   • Page Load
                   • Page Change
                   • Page Transitions
                   • Page Initialization
                   • Page Remove
                   • Layout

Wednesday, November 7, 12
Page Load
                   • pagebeforeload
                   • pageload
                   • pageloadfailed




Wednesday, November 7, 12
Page Change
                   • pagebeforechange
                   • pagechange
                   • pagechangefailed




Wednesday, November 7, 12
Page Transition
                   • pagebeforeshow
                   • pageshow
                   • pagebeforehide
                   • pagehide



Wednesday, November 7, 12
Page Create
                   • pagebeforecreate
                   • pagecreate
                   • pageinit




Wednesday, November 7, 12
Miscellaneous
                   • pageremove
                   • updatelayout
                   • orientationchange




Wednesday, November 7, 12
page events demo



Wednesday, November 7, 12
PerformanceTips
                   • Watch the size of the DOM
                   • Selectors
                    • Narrow Them
                    • Cache Them
                   • Reference the active Page


Wednesday, November 7, 12
Hands-on Exercise




Wednesday, November 7, 12
Hands-on Exercise
                   • Using jsFiddle.net, create a simply jQuery
                            Mobile page




Wednesday, November 7, 12
Hands-on Exercise
                   • Using jsFiddle.net, create a simply jQuery
                            Mobile page
                   • It should have a header, a footer, and at
                            least on form element on the page




Wednesday, November 7, 12
Backbone.js



Wednesday, November 7, 12
Backbone supplies structure to JavaScript-heavy
    applications by providing models with key-value binding
    and custom events, collections with a rich API of
    enumerable functions, views with declarative event
    handling, and connects it all to your existing application
    over a RESTful JSON interface.

    Requires Underscore and jQuery.




Wednesday, November 7, 12
Underscore is a utility-belt library for JavaScript that
     provides a lot of the functional programming support
     that you would expect in Prototype.js (or Ruby), but
     without extending any of the built-in JavaScript objects. 




Wednesday, November 7, 12
Backbone.js
                   •        Handles the data on client

                   •        Models

                   •        Views

                   •        Collections




Wednesday, November 7, 12
Models



Wednesday, November 7, 12
Views



Wednesday, November 7, 12
Collections



Wednesday, November 7, 12
Summary
                   • Typeof
                   • Functions
                   • Exceptions
                   • The History Object
                   • jQuery Mobile
                   • Backbone.js
Wednesday, November 7, 12

Weitere ähnliche Inhalte

Was ist angesagt?

From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)jaxLondonConference
 
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMorning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMongoDB
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Tomer Gabel
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryTomer Gabel
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummiesAzrul MADISA
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediZeroTurnaround
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java InteropAndrey Breslav
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
 
[A4]de view2012 scala-michinisougu
[A4]de view2012 scala-michinisougu[A4]de view2012 scala-michinisougu
[A4]de view2012 scala-michinisouguNAVER D2
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Heiko Behrens
 

Was ist angesagt? (20)

From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
 
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic ConceptsMorning with MongoDB Paris 2012 - MongoDB Basic Concepts
Morning with MongoDB Paris 2012 - MongoDB Basic Concepts
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummies
 
hibernate
hibernatehibernate
hibernate
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila Szegedi
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
[A4]de view2012 scala-michinisougu
[A4]de view2012 scala-michinisougu[A4]de view2012 scala-michinisougu
[A4]de view2012 scala-michinisougu
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
 

Andere mochten auch

AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day OneTroy Miles
 
Mean Stack - An Overview
Mean Stack - An OverviewMean Stack - An Overview
Mean Stack - An OverviewNaveen Pete
 
Cross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-jsCross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-jsTroy Miles
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1Troy Miles
 
Building A Web App In 100% JavaScript with Carl Bergenhem
 Building A Web App In 100% JavaScript with Carl Bergenhem Building A Web App In 100% JavaScript with Carl Bergenhem
Building A Web App In 100% JavaScript with Carl BergenhemFITC
 
CSS之继承详解
CSS之继承详解CSS之继承详解
CSS之继承详解张 鑫旭
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialPHP Support
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You KnewTroy Miles
 
基于Seajs的项目构建
基于Seajs的项目构建基于Seajs的项目构建
基于Seajs的项目构建Zhang Xiaoxue
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEANTroy Miles
 
Hybrid app简要介绍
Hybrid app简要介绍Hybrid app简要介绍
Hybrid app简要介绍Eric Xiao
 
Enterprise javascriptsession2
Enterprise javascriptsession2Enterprise javascriptsession2
Enterprise javascriptsession2Troy Miles
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-upTroy Miles
 
Enterprise javascriptsession1
Enterprise javascriptsession1Enterprise javascriptsession1
Enterprise javascriptsession1Troy Miles
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveXTroy Miles
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsTroy Miles
 
AngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkAngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkTroy Miles
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Expressjguerrero999
 
Express: A Jump-Start
Express: A Jump-StartExpress: A Jump-Start
Express: A Jump-StartNaveen Pete
 

Andere mochten auch (20)

AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
Mean Stack - An Overview
Mean Stack - An OverviewMean Stack - An Overview
Mean Stack - An Overview
 
Cross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-jsCross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-js
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1
 
Building A Web App In 100% JavaScript with Carl Bergenhem
 Building A Web App In 100% JavaScript with Carl Bergenhem Building A Web App In 100% JavaScript with Carl Bergenhem
Building A Web App In 100% JavaScript with Carl Bergenhem
 
CSS之继承详解
CSS之继承详解CSS之继承详解
CSS之继承详解
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You Knew
 
基于Seajs的项目构建
基于Seajs的项目构建基于Seajs的项目构建
基于Seajs的项目构建
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
Hybrid app简要介绍
Hybrid app简要介绍Hybrid app简要介绍
Hybrid app简要介绍
 
Enterprise javascriptsession2
Enterprise javascriptsession2Enterprise javascriptsession2
Enterprise javascriptsession2
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
 
Enterprise javascriptsession1
Enterprise javascriptsession1Enterprise javascriptsession1
Enterprise javascriptsession1
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveX
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
AngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkAngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic Framework
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Express: A Jump-Start
Express: A Jump-StartExpress: A Jump-Start
Express: A Jump-Start
 

Ähnlich wie JavaScript Session 3 - History and the Rest

Javascript the Language of the Web
Javascript the Language of the WebJavascript the Language of the Web
Javascript the Language of the Webandersjanmyr
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1Kasia Drzyzga
 
Charla ruby nscodermad
Charla ruby nscodermadCharla ruby nscodermad
Charla ruby nscodermadnscoder_mad
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionClaudio Martella
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyBlazing Cloud
 
Rspec group
Rspec groupRspec group
Rspec groupthefonso
 
Mastering the shortcode api
Mastering the shortcode apiMastering the shortcode api
Mastering the shortcode apiPeter Baylies
 
Morning with MongoDB Paris 2012 - Accueil et Introductions
Morning with MongoDB Paris 2012 - Accueil et IntroductionsMorning with MongoDB Paris 2012 - Accueil et Introductions
Morning with MongoDB Paris 2012 - Accueil et IntroductionsMongoDB
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyajuckel
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml MappingMarc Seeger
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 

Ähnlich wie JavaScript Session 3 - History and the Rest (20)

Javascript the Language of the Web
Javascript the Language of the WebJavascript the Language of the Web
Javascript the Language of the Web
 
JavaScript 1.8.5: New Features Explored
JavaScript 1.8.5:  New Features ExploredJavaScript 1.8.5:  New Features Explored
JavaScript 1.8.5: New Features Explored
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
 
Charla ruby nscodermad
Charla ruby nscodermadCharla ruby nscodermad
Charla ruby nscodermad
 
Everyday - mongodb
Everyday - mongodbEveryday - mongodb
Everyday - mongodb
 
Hadoop: A Hands-on Introduction
Hadoop: A Hands-on IntroductionHadoop: A Hands-on Introduction
Hadoop: A Hands-on Introduction
 
JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
Rspec group
Rspec groupRspec group
Rspec group
 
JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
 
Js in the open
Js in the openJs in the open
Js in the open
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Euruko 2012 - JRuby
Euruko 2012 - JRubyEuruko 2012 - JRuby
Euruko 2012 - JRuby
 
Mastering the shortcode api
Mastering the shortcode apiMastering the shortcode api
Mastering the shortcode api
 
Morning with MongoDB Paris 2012 - Accueil et Introductions
Morning with MongoDB Paris 2012 - Accueil et IntroductionsMorning with MongoDB Paris 2012 - Accueil et Introductions
Morning with MongoDB Paris 2012 - Accueil et Introductions
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 

Mehr von Troy Miles

Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web ServersTroy Miles
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with KotlinTroy Miles
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?Troy Miles
 
Angular Weekend
Angular WeekendAngular Weekend
Angular WeekendTroy Miles
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN StackTroy Miles
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScriptTroy Miles
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in ClojureTroy Miles
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutesTroy Miles
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript TipsTroy Miles
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkTroy Miles
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day trainingTroy Miles
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Troy Miles
 

Mehr von Troy Miles (20)

Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web Servers
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
ReactJS.NET
ReactJS.NETReactJS.NET
ReactJS.NET
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 

JavaScript Session 3 - History and the Rest

  • 1. Enterprise JavaScript Session 3 - History and the Rest Wednesday, November 7, 12
  • 2. Hi, I’m Troy Wednesday, November 7, 12
  • 3. Hi, I’m Troy • Developing software Since 1979 • Initially Game Software in Assembly (6502 and x86) • Currently JavaScript, C#, Java, Objective-C • rockncoder@gmail.com Wednesday, November 7, 12
  • 4. jssaturday.com Nov. 10th, Long Beach Convention Center Discount code: RiaConsultingLLC Save $65!!! Wednesday, November 7, 12
  • 6. Today’s Agenda • Somethings We Missed Wednesday, November 7, 12
  • 7. Today’s Agenda • Somethings We Missed • The History Object Wednesday, November 7, 12
  • 8. Today’s Agenda • Somethings We Missed • The History Object • jQuery Mobile Wednesday, November 7, 12
  • 9. Today’s Agenda • Somethings We Missed • The History Object • jQuery Mobile • Backbone.js Wednesday, November 7, 12
  • 10. Somethings We Missed • Typeof • Functions • Exceptions Wednesday, November 7, 12
  • 11. typeof • The typeof operator detects the type of an object • It evaluates to a string which represents the object’s type • Unfortunately it is broken Wednesday, November 7, 12
  • 12. typeof var msg = “hello there”; var bob = typeof msg; console.log(“msg is of type” + bob); /* prints - msg is of type string */ Wednesday, November 7, 12
  • 13. Type typeof Object “object” Array “object” Function “function” String “string” Number “number” Boolean “boolean” null “object” undefined “undefined” Wednesday, November 7, 12
  • 15. Function Properties • The “this” parameter • The arguments parameter • call & apply methods • length property Wednesday, November 7, 12
  • 16. The “this” parameter • Functions receive two hidden parameters • The first hidden parameter is this • It holds the context of the object which called the function • When called from global space, this points to the window object • Can modify the calling object via this Wednesday, November 7, 12
  • 17. The arguments parameter • The second hidden parameter is arguments • It contains a list of all the parameter passed to the function • arguments is array-like, values in it can be index, but no other array methods Wednesday, November 7, 12
  • 19. call & apply methods • The call & apply methods both allow you to pass the this object to a function • The difference is in how you pass parameters to the function • call: parameters sent individually • apply: parameters sent in an array Wednesday, November 7, 12
  • 20. call & apply methods demo Wednesday, November 7, 12
  • 21. The length property • The length property holds the number parameters the function was declared with Wednesday, November 7, 12
  • 24. Hands-on Exercise • Use arguments to create a function, calcSum, which returns the sum of an unknown number of numbers passed to it Wednesday, November 7, 12
  • 25. Hands-on Exercise • Use arguments to create a function, calcSum, which returns the sum of an unknown number of numbers passed to it • The following should all work: calcSum(1,2,3); calcSum(4,5,6,7,8); calcSum(100,200,450,74); Wednesday, November 7, 12
  • 26. Hands-on Exercise, pt. 2 Wednesday, November 7, 12
  • 27. Hands-on Exercise, pt. 2 • Make the calcSum function more robust by filtering non-numbers out of the summing function Wednesday, November 7, 12
  • 28. Hands-on Exercise, pt. 2 • Make the calcSum function more robust by filtering non-numbers out of the summing function • The following should all work: calcSum(1,2, true,3); calcSum(4,5,”bob”,6,7,8); calcSum(100,200,calcSum,450,74); Wednesday, November 7, 12
  • 29. Exceptions • Like other languages JavaScript has exceptions • The exceptions can also be thrown using the throw statement: if(typeof a !== ‘number’ || typeof b !== ‘number’){ throw { name: ‘TypeError’, message: ‘add needs numbers‘ }; } Wednesday, November 7, 12
  • 30. Exceptions function calcBob () { try { /* operation which might generate an exception */ } catch(e) { /* handle exception */ } } Wednesday, November 7, 12
  • 32. The History Problem • Modern JavaScript web apps have three problems with regards to history: • They aren’t navigate-able by web crawlers • They don’t have bookmark-able URLs • They don’t behave correctly Wednesday, November 7, 12
  • 34. The History Object • The History Object is part of the window object • The API is very small, three methods and one property • methods: back(), forward(), go() • Properties: length Wednesday, November 7, 12
  • 35. The History Object • The History object can only move forward or backwards to places the user has already been • Not able to add items to history • Not very useful Wednesday, November 7, 12
  • 36. HTML5 History • pushState() • replaceState() • popstate event • history.state Wednesday, November 7, 12
  • 37. pushState() • pushState(state, title, URL); • state - a JS object associated with the new history entry • title - currently ignored by browser • URL - the new history entry’s URL Wednesday, November 7, 12
  • 38. replaceState() • replaceState(state, title, URL); • Behaves exactly like pushState except it modifies the current history entry instead of creating a new one Wednesday, November 7, 12
  • 39. popstate event • A popstate event is fired by the browser every time the active history entry changes Wednesday, November 7, 12
  • 40. history.state • var currentState = history.state; • Allows you to read the current state of the history object Wednesday, November 7, 12
  • 41. History polyfills • HTML5 pushState is supported on most modern browsers • Older browsers will need to use a polyfill like History.js Wednesday, November 7, 12
  • 43. https://github.com/ balupton/history.js/wiki/ Intelligent-State-Handling Wednesday, November 7, 12
  • 45. Quick Intro to jQuery Mobile A unified, HTML5-based user interface system for all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily theme-able design. Wednesday, November 7, 12
  • 47. Page Structure • Header • Footer • Content Area Wednesday, November 7, 12
  • 48. Header • Page Title • Left Button • Right Button Wednesday, November 7, 12
  • 49. Footer • Title • Buttons Wednesday, November 7, 12
  • 50. Content Area This is where your stuff goes. Wednesday, November 7, 12
  • 51. How It Works • Dynamic DOM Manipulation • HTML5 Pseudo-Attributes • There is no free lunch Wednesday, November 7, 12
  • 52. Dynamic DOM Manipulation demo Wednesday, November 7, 12
  • 53. HTML5 Pseudo- Attributes • JQM Uses Pseudo-Attributes (data-) • Standard Browser Behavior - Ignore Unknown Attributes • Allows for Some Functionality on low-end browsers Wednesday, November 7, 12
  • 54. Form Elements (aka widgets) • buttons • sliders • radio buttons • checkboxes • select menus • etc. Wednesday, November 7, 12
  • 55. Lists • Basic Lists • Nested Lists • List Dividers • Split Lists • etc. Wednesday, November 7, 12
  • 56. Multi-Page Apps • basic setup • transitions • passing data between pages Wednesday, November 7, 12
  • 58. Touch • tap • taphold • swipe • swipeleft • swiperight Wednesday, November 7, 12
  • 59. Page • Page Load • Page Change • Page Transitions • Page Initialization • Page Remove • Layout Wednesday, November 7, 12
  • 60. Page Load • pagebeforeload • pageload • pageloadfailed Wednesday, November 7, 12
  • 61. Page Change • pagebeforechange • pagechange • pagechangefailed Wednesday, November 7, 12
  • 62. Page Transition • pagebeforeshow • pageshow • pagebeforehide • pagehide Wednesday, November 7, 12
  • 63. Page Create • pagebeforecreate • pagecreate • pageinit Wednesday, November 7, 12
  • 64. Miscellaneous • pageremove • updatelayout • orientationchange Wednesday, November 7, 12
  • 65. page events demo Wednesday, November 7, 12
  • 66. PerformanceTips • Watch the size of the DOM • Selectors • Narrow Them • Cache Them • Reference the active Page Wednesday, November 7, 12
  • 68. Hands-on Exercise • Using jsFiddle.net, create a simply jQuery Mobile page Wednesday, November 7, 12
  • 69. Hands-on Exercise • Using jsFiddle.net, create a simply jQuery Mobile page • It should have a header, a footer, and at least on form element on the page Wednesday, November 7, 12
  • 71. Backbone supplies structure to JavaScript-heavy applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface. Requires Underscore and jQuery. Wednesday, November 7, 12
  • 72. Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.  Wednesday, November 7, 12
  • 73. Backbone.js • Handles the data on client • Models • Views • Collections Wednesday, November 7, 12
  • 77. Summary • Typeof • Functions • Exceptions • The History Object • jQuery Mobile • Backbone.js Wednesday, November 7, 12