SlideShare a Scribd company logo
Write Better JavaScript


      Kevin Whinnery
Kevin Whinnery
Engineer and Platform Evangelist
Appcelerator since 2008

Husband and father of three:




Web developer and JavaScript slinger
turned mobile and desktop hacker.

http://kevinwhinnery.com
http://twitter.com/kevinwhinnery
http://github.com/kwhinnery
Agenda
•  The Good Parts and Bad Parts

•  Object-Oriented Programming
   in JavaScript

•  Useful JavaScript Patterns,
   Tricks, and Style Guidelines

•  JavaScript in Titanium Mobile

•  Further Reading
JavaScript is a
  tragically
misunderstood
  language.
“JavaScript is the
 incredibly hot girl at the
party that brings her loser
     boyfriend DOM”
           Tom Robinson
         Founder, 280 North
JavaScript – What is it good for?
•  Absolutely nothing? Far from it…

•  Object-Oriented (Prototypical Inheritance)… or not

•  Flexible Objects

•  First-Class Functions

•  Built for event-driven UI
JavaScript: The Good Parts
•  Published In 2008 by Doug
   Crockford

•  Covers the good and bad

•  I use patterns from this book
   every time I write JS

•  Buy/read/love
Some Bad Parts
Global Variables
app.js




                   some/library.js
Truthy and Falsy
•  Falsy Values:
   •    false
   •    0
   •    ‘’
   •    null
   •    undefined
   •    NaN


•  Truthy Values:
   •  Everything else


•  Almost always, you
   want === and !==
Floating Point Arithmetic




       Avoid this by converting to whole numbers, and
                 converting back to decimal.
typeof is a liar
there’s more (http://wtfjs.com ),
        but let’s skip to…
The Good Parts
Expressive Object Literals
Easy Object Serialization
First Class Functions
Flexible Objects
Duck Typing
…plus it’s EVERYWHERE.
one could develop all kinds of software
    applications with nothing else.
OOP!
(There it is!)
JavaScript has Prototypal Inheritance,
  which creates new copies of objects
from an existing object (the prototype)


       there’s much more to it than this, but we’ll keep it
                      mostly high level…
Object Constructors

    * The capital first letter is by convention, not requirement.
Object Prototype
we could have also wrote…
…but object instantiation using the
  prototype to define functions/
       properties is faster.


     http://ejohn.org/blog/simple-class-instantiation
          mentions this and other methods for…
Inheritance (One Approach)
JavaScript doesn’t support multiple
 inheritance, but there are multiple
libraries that handle that and more,
       including underscore.js


    http://documentcloud.github.com/underscore/#extend
Parasitic Inheritance
•  Create an existing object

•  Add new features and functionality to it (the parasites,
   if you will)

•  Pass it off as an instance of a new object

•  Slightly slower than .prototype but more flexible (and
   inescapable in certain cases)
Parasitic Inheritance
Useful Tricks
Self-Calling Function
•  Function scope is
   the only scope in
   JavaScript

•  Self-calling
   function provides
   encapsulation

•  Both forms at
   right are valid,
   second is
   preferred
Module Pattern
•  Necessary for
   <script> in the
   browser or
   Ti.include

•  Uses functional
   scope to provide a
   public interface to
   a module

•  Tweetanium/
   Training demos use
   a version of this
Dynamic Function Signatures
•  Not necessary to explicitly name parameters

•  Function interfaces can rationalize many input types

•  jQuery does this well, and is very popular b/c of its API
Call And Apply
•  Functions are first class objects

•  Passable, and callable

•  Can replace “this” inside function with something more
   useful

•  call: call a function with known arguments

•  apply: call a function with an array of arguments
Apply Example
Call Example
A More Useful “this”
Style   Guidelines
Style “Dos”
•  Use descriptive variable names (exception: well-
   understood, frequently typed modules/libraries, like
   “Ti” or “_” for Underscore.js)

•  JavaScript file contents (cohesion)

•  Google Style Guidelines: http://bit.ly/g_style

•  Follow the above and you are good to go
Style “Don’ts”
•  terse local variable names – excuse me if I don’t know
   what “tvr” means inside your 300 line constructor

•  Huge files – if you want to write 13,000 lines in a file,
   go back to enterprise Java

•  Semicolons are not optional – you don’t want the
   interpreter writing code for you

•  and these monstrosities…
Curly braces on the next line




*this style will actually break in some environments (semicolon insertion)
Unnecessary Indentation
JavaScript in
Titanium Mobile
JavaScript Engines
•  iOS – JavaScriptCore – C-based, pretty darn fast

•  Android – Rhino – Java-based, meant for the server-side
   or desktop, just okay in terms of performance

•  Coming soon – Android/V8 – C-based, super duper fast,
   minimum Android version 2.2 (don’t freak out, check
   the version distribution stats)

•  Android: Very important not to load all scripts up front
   in large applications (slow)
Titanium Features
•  Built-in JSON serialization

•  CommonJS Module Spec

•  Proxy objects are special – what’s a proxy? A stand-in
   for a native object, like anything you get back from
   something like:
What’s special about proxies?
•  You can’t modify the prototype

•  You can’t add functions or properties that start with
   “get” or “set” – these are magic in Titanium proxies:
Further Reading
Books and Reference
•  Mozilla Developer Network JavaScript Reference

•  JavaScript: The Good Parts

•  Eloquent JavaScript (free!)

•  High Performance JavaScript

•  JavaScript Patterns
Not Exhaustive “Must Follow” List
•    @kevinwhinnery J
•    @BrendanEich
•    @functionsource
•    @dalmaer
•    @thomasfuchs
•    @zacharyjohnson
•    @wycats
•    @DavidKaneda
•    @rem
•    @dawsontoth (Titanium goodness)
Potpourri
•  http://javascriptweekly.com - seriously, stop what
   you’re doing and go there right now

•  http://badassjs.com - then, after that, go here

•  http://jsbin.com - handy test harness

•  https://github.com/cjohansen/juicer - Great
   compression and obfuscation utility (Ruby)

•  http://crockford.com - Pay your respects
Questions?
Thank You!

More Related Content

What's hot

Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
Kevin Whinnery
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
Udaya Kumar
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
Alessandro Giorgetti
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Mike Pence
 
TypeScript
TypeScriptTypeScript
CatalystX::SimpleLogin
CatalystX::SimpleLoginCatalystX::SimpleLogin
CatalystX::SimpleLogin
Tomas Doran
 
Migrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to GoMigrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to Go
Weng Wei
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
Ben McCormick
 
Mixing Plone and Django for explosive results
Mixing Plone and Django for explosive resultsMixing Plone and Django for explosive results
Mixing Plone and Django for explosive results
Simone Deponti
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
Weng Wei
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
 
Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016
petecarapetyan
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
Remo Jansen
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
felixbillon
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
akhilsreyas
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
Gil Fink
 
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Oren Rubin
 

What's hot (20)

Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional ProgrammingInto the Land of lambda, One Programmer's Journey Into Functional Programming
Into the Land of lambda, One Programmer's Journey Into Functional Programming
 
TypeScript
TypeScriptTypeScript
TypeScript
 
CatalystX::SimpleLogin
CatalystX::SimpleLoginCatalystX::SimpleLogin
CatalystX::SimpleLogin
 
Migrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to GoMigrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to Go
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
Mixing Plone and Django for explosive results
Mixing Plone and Django for explosive resultsMixing Plone and Django for explosive results
Mixing Plone and Django for explosive results
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
Statistical Element Locator by Oren Rubin - SeleniumConf UK 2016
 

Viewers also liked

Ben Morgan - AGI Asset Management SIG (Sep 2013)
Ben Morgan - AGI Asset Management SIG (Sep 2013)Ben Morgan - AGI Asset Management SIG (Sep 2013)
Ben Morgan - AGI Asset Management SIG (Sep 2013)
GeoEnable Limited
 
Upgrading the web
Upgrading the webUpgrading the web
Upgrading the web
Roman Gafurov
 
JavaScript Jump Start
JavaScript Jump StartJavaScript Jump Start
JavaScript Jump Start
Haim Michael
 
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
Daniel Fisher
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
Daniel Fisher
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
Daniel Fisher
 

Viewers also liked (6)

Ben Morgan - AGI Asset Management SIG (Sep 2013)
Ben Morgan - AGI Asset Management SIG (Sep 2013)Ben Morgan - AGI Asset Management SIG (Sep 2013)
Ben Morgan - AGI Asset Management SIG (Sep 2013)
 
Upgrading the web
Upgrading the webUpgrading the web
Upgrading the web
 
JavaScript Jump Start
JavaScript Jump StartJavaScript Jump Start
JavaScript Jump Start
 
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragilityMD DevdDays 2016: Defensive programming, resilience patterns & antifragility
MD DevdDays 2016: Defensive programming, resilience patterns & antifragility
 
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
2010 - Basta!: REST mit WCF 4, Silverlight und AJAX
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
 

Similar to Kevin Whinnery: Write Better JavaScript

Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
Kevin Whinnery
 
Frontend as a first class citizen
Frontend as a first class citizenFrontend as a first class citizen
Frontend as a first class citizen
Marcin Grzywaczewski
 
Javascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to TitaniumJavascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to Titanium
Techday7
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
Dhaval Barot
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
eightbit
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
Marco Breveglieri
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
lokeshpappaka10
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
Togakangaroo
 
TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)
Igor Talevski
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
PraveenKumar680401
 
Isomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the web
Sigma Software
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
eightbit
 
JS Essence
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
Jayanga V. Liyanage
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
Troy Miles
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
Sargis Sargsyan
 
Introduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScriptIntroduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScript
Jakob Torp
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
Jared Faris
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UI
Marcin Grzywaczewski
 

Similar to Kevin Whinnery: Write Better JavaScript (20)

Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
 
Frontend as a first class citizen
Frontend as a first class citizenFrontend as a first class citizen
Frontend as a first class citizen
 
Javascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to TitaniumJavascript Best Practices and Intro to Titanium
Javascript Best Practices and Intro to Titanium
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
 
Isomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the web
 
Rootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift ApplicationsRootcon X - Reverse Engineering Swift Applications
Rootcon X - Reverse Engineering Swift Applications
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
Introduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScriptIntroduction to the wonderful world of JavaScript
Introduction to the wonderful world of JavaScript
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UI
 

More from Axway Appcelerator

Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & RoadmapAxway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator
 
2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie
Axway Appcelerator
 
Making the Mobile Mind Shift
Making the Mobile Mind ShiftMaking the Mobile Mind Shift
Making the Mobile Mind Shift
Axway Appcelerator
 
Stop Debating, Start Measuring
Stop Debating, Start MeasuringStop Debating, Start Measuring
Stop Debating, Start Measuring
Axway Appcelerator
 
Mobile & The New Experience Economy (And What it Means for IT)
Mobile & The New Experience Economy  (And What it Means for IT)Mobile & The New Experience Economy  (And What it Means for IT)
Mobile & The New Experience Economy (And What it Means for IT)
Axway Appcelerator
 
Apps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really MeansApps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really Means
Axway Appcelerator
 
Appcelerator Presentation Template
Appcelerator Presentation TemplateAppcelerator Presentation Template
Appcelerator Presentation Template
Axway Appcelerator
 
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote   jonathan rende, appcelerator's vp of productsCodestrong 2012 keynote   jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Axway Appcelerator
 
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote   jeff haynie, appcelerator's ceoCodestrong 2012 keynote   jeff haynie, appcelerator's ceo
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Axway Appcelerator
 
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 keynote   how to build a top ten appCodestrong 2012 keynote   how to build a top ten app
Codestrong 2012 keynote how to build a top ten app
Axway Appcelerator
 
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session  at&t api platform and trendsCodestrong 2012 breakout session  at&t api platform and trends
Codestrong 2012 breakout session at&t api platform and trends
Axway Appcelerator
 
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session   what's new in titanium studioCodestrong 2012 breakout session   what's new in titanium studio
Codestrong 2012 breakout session what's new in titanium studio
Axway Appcelerator
 
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session   using appcelerator cloud services in your ...Codestrong 2012 breakout session   using appcelerator cloud services in your ...
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Axway Appcelerator
 
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session   the role of cloud services in your next ge...Codestrong 2012 breakout session   the role of cloud services in your next ge...
Codestrong 2012 breakout session the role of cloud services in your next ge...
Axway Appcelerator
 
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session   new device platform support for titaniumCodestrong 2012 breakout session   new device platform support for titanium
Codestrong 2012 breakout session new device platform support for titanium
Axway Appcelerator
 
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session   mobile platform and infrastructureCodestrong 2012 breakout session   mobile platform and infrastructure
Codestrong 2012 breakout session mobile platform and infrastructure
Axway Appcelerator
 
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session   making money on appcelerator's marketplaceCodestrong 2012 breakout session   making money on appcelerator's marketplace
Codestrong 2012 breakout session making money on appcelerator's marketplace
Axway Appcelerator
 
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session   live multi-platform testingCodestrong 2012 breakout session   live multi-platform testing
Codestrong 2012 breakout session live multi-platform testing
Axway Appcelerator
 
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session   leveraging titanium as part of your mobile...Codestrong 2012 breakout session   leveraging titanium as part of your mobile...
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Axway Appcelerator
 
Codestrong 2012 breakout session i os internals and best practices
Codestrong 2012 breakout session   i os internals and best practicesCodestrong 2012 breakout session   i os internals and best practices
Codestrong 2012 breakout session i os internals and best practices
Axway Appcelerator
 

More from Axway Appcelerator (20)

Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & RoadmapAxway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
 
2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie2014 Dublin Web Summit by Jeff Haynie
2014 Dublin Web Summit by Jeff Haynie
 
Making the Mobile Mind Shift
Making the Mobile Mind ShiftMaking the Mobile Mind Shift
Making the Mobile Mind Shift
 
Stop Debating, Start Measuring
Stop Debating, Start MeasuringStop Debating, Start Measuring
Stop Debating, Start Measuring
 
Mobile & The New Experience Economy (And What it Means for IT)
Mobile & The New Experience Economy  (And What it Means for IT)Mobile & The New Experience Economy  (And What it Means for IT)
Mobile & The New Experience Economy (And What it Means for IT)
 
Apps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really MeansApps, APIs & Analytics: What "Mobile First" Really Means
Apps, APIs & Analytics: What "Mobile First" Really Means
 
Appcelerator Presentation Template
Appcelerator Presentation TemplateAppcelerator Presentation Template
Appcelerator Presentation Template
 
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote   jonathan rende, appcelerator's vp of productsCodestrong 2012 keynote   jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
 
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote   jeff haynie, appcelerator's ceoCodestrong 2012 keynote   jeff haynie, appcelerator's ceo
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
 
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 keynote   how to build a top ten appCodestrong 2012 keynote   how to build a top ten app
Codestrong 2012 keynote how to build a top ten app
 
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session  at&t api platform and trendsCodestrong 2012 breakout session  at&t api platform and trends
Codestrong 2012 breakout session at&t api platform and trends
 
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session   what's new in titanium studioCodestrong 2012 breakout session   what's new in titanium studio
Codestrong 2012 breakout session what's new in titanium studio
 
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session   using appcelerator cloud services in your ...Codestrong 2012 breakout session   using appcelerator cloud services in your ...
Codestrong 2012 breakout session using appcelerator cloud services in your ...
 
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session   the role of cloud services in your next ge...Codestrong 2012 breakout session   the role of cloud services in your next ge...
Codestrong 2012 breakout session the role of cloud services in your next ge...
 
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session   new device platform support for titaniumCodestrong 2012 breakout session   new device platform support for titanium
Codestrong 2012 breakout session new device platform support for titanium
 
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session   mobile platform and infrastructureCodestrong 2012 breakout session   mobile platform and infrastructure
Codestrong 2012 breakout session mobile platform and infrastructure
 
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session   making money on appcelerator's marketplaceCodestrong 2012 breakout session   making money on appcelerator's marketplace
Codestrong 2012 breakout session making money on appcelerator's marketplace
 
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session   live multi-platform testingCodestrong 2012 breakout session   live multi-platform testing
Codestrong 2012 breakout session live multi-platform testing
 
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session   leveraging titanium as part of your mobile...Codestrong 2012 breakout session   leveraging titanium as part of your mobile...
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
 
Codestrong 2012 breakout session i os internals and best practices
Codestrong 2012 breakout session   i os internals and best practicesCodestrong 2012 breakout session   i os internals and best practices
Codestrong 2012 breakout session i os internals and best practices
 

Recently uploaded

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 

Kevin Whinnery: Write Better JavaScript

  • 1. Write Better JavaScript Kevin Whinnery
  • 2. Kevin Whinnery Engineer and Platform Evangelist Appcelerator since 2008 Husband and father of three: Web developer and JavaScript slinger turned mobile and desktop hacker. http://kevinwhinnery.com http://twitter.com/kevinwhinnery http://github.com/kwhinnery
  • 3. Agenda •  The Good Parts and Bad Parts •  Object-Oriented Programming in JavaScript •  Useful JavaScript Patterns, Tricks, and Style Guidelines •  JavaScript in Titanium Mobile •  Further Reading
  • 4. JavaScript is a tragically misunderstood language.
  • 5. “JavaScript is the incredibly hot girl at the party that brings her loser boyfriend DOM” Tom Robinson Founder, 280 North
  • 6. JavaScript – What is it good for? •  Absolutely nothing? Far from it… •  Object-Oriented (Prototypical Inheritance)… or not •  Flexible Objects •  First-Class Functions •  Built for event-driven UI
  • 7. JavaScript: The Good Parts •  Published In 2008 by Doug Crockford •  Covers the good and bad •  I use patterns from this book every time I write JS •  Buy/read/love
  • 9. Global Variables app.js some/library.js
  • 10. Truthy and Falsy •  Falsy Values: •  false •  0 •  ‘’ •  null •  undefined •  NaN •  Truthy Values: •  Everything else •  Almost always, you want === and !==
  • 11. Floating Point Arithmetic Avoid this by converting to whole numbers, and converting back to decimal.
  • 12. typeof is a liar
  • 13. there’s more (http://wtfjs.com ), but let’s skip to…
  • 20. …plus it’s EVERYWHERE. one could develop all kinds of software applications with nothing else.
  • 22. JavaScript has Prototypal Inheritance, which creates new copies of objects from an existing object (the prototype) there’s much more to it than this, but we’ll keep it mostly high level…
  • 23. Object Constructors * The capital first letter is by convention, not requirement.
  • 25. we could have also wrote…
  • 26. …but object instantiation using the prototype to define functions/ properties is faster. http://ejohn.org/blog/simple-class-instantiation mentions this and other methods for…
  • 28. JavaScript doesn’t support multiple inheritance, but there are multiple libraries that handle that and more, including underscore.js http://documentcloud.github.com/underscore/#extend
  • 29. Parasitic Inheritance •  Create an existing object •  Add new features and functionality to it (the parasites, if you will) •  Pass it off as an instance of a new object •  Slightly slower than .prototype but more flexible (and inescapable in certain cases)
  • 32. Self-Calling Function •  Function scope is the only scope in JavaScript •  Self-calling function provides encapsulation •  Both forms at right are valid, second is preferred
  • 33. Module Pattern •  Necessary for <script> in the browser or Ti.include •  Uses functional scope to provide a public interface to a module •  Tweetanium/ Training demos use a version of this
  • 34. Dynamic Function Signatures •  Not necessary to explicitly name parameters •  Function interfaces can rationalize many input types •  jQuery does this well, and is very popular b/c of its API
  • 35. Call And Apply •  Functions are first class objects •  Passable, and callable •  Can replace “this” inside function with something more useful •  call: call a function with known arguments •  apply: call a function with an array of arguments
  • 38. A More Useful “this”
  • 39. Style Guidelines
  • 40. Style “Dos” •  Use descriptive variable names (exception: well- understood, frequently typed modules/libraries, like “Ti” or “_” for Underscore.js) •  JavaScript file contents (cohesion) •  Google Style Guidelines: http://bit.ly/g_style •  Follow the above and you are good to go
  • 41. Style “Don’ts” •  terse local variable names – excuse me if I don’t know what “tvr” means inside your 300 line constructor •  Huge files – if you want to write 13,000 lines in a file, go back to enterprise Java •  Semicolons are not optional – you don’t want the interpreter writing code for you •  and these monstrosities…
  • 42. Curly braces on the next line *this style will actually break in some environments (semicolon insertion)
  • 45. JavaScript Engines •  iOS – JavaScriptCore – C-based, pretty darn fast •  Android – Rhino – Java-based, meant for the server-side or desktop, just okay in terms of performance •  Coming soon – Android/V8 – C-based, super duper fast, minimum Android version 2.2 (don’t freak out, check the version distribution stats) •  Android: Very important not to load all scripts up front in large applications (slow)
  • 46. Titanium Features •  Built-in JSON serialization •  CommonJS Module Spec •  Proxy objects are special – what’s a proxy? A stand-in for a native object, like anything you get back from something like:
  • 47. What’s special about proxies? •  You can’t modify the prototype •  You can’t add functions or properties that start with “get” or “set” – these are magic in Titanium proxies:
  • 49. Books and Reference •  Mozilla Developer Network JavaScript Reference •  JavaScript: The Good Parts •  Eloquent JavaScript (free!) •  High Performance JavaScript •  JavaScript Patterns
  • 50. Not Exhaustive “Must Follow” List •  @kevinwhinnery J •  @BrendanEich •  @functionsource •  @dalmaer •  @thomasfuchs •  @zacharyjohnson •  @wycats •  @DavidKaneda •  @rem •  @dawsontoth (Titanium goodness)
  • 51. Potpourri •  http://javascriptweekly.com - seriously, stop what you’re doing and go there right now •  http://badassjs.com - then, after that, go here •  http://jsbin.com - handy test harness •  https://github.com/cjohansen/juicer - Great compression and obfuscation utility (Ruby) •  http://crockford.com - Pay your respects