Javascript Update May 2013

Ramesh Nair
Ramesh NairFreelance Software Developer at HiddenTao Ltd
The Javascript Update
Ramesh Nair
ram@hiddentao.com
http://twitter.com/hiddentao
Where Javascript is at - May 2013
What this talk will cover
● Javascript history
● Language overview
● Browser goodies
● Front-end ecosystem
● Back-end: Node.js
● Variations and alternatives, e.g. CoffeeScript
● The cutting edge – future stuff
● How to stay up-to-date
Evolution
● Created in 1995 at Netscape
● Mocha → LiveScript → JavaScript
● Accepted by ECMA by 1997
– ECMAScript is official standard name
– Javascript = JScript (Internet Explorer)
● v3 (JS 1.5) set the standard
● ECMA TC39 working on ES.next, Harmony
Language overview
● Built-in types: Boolean, Number, String, null, undefined
– Strings are UTF-16
● Dynamically typed
● Objects work as hash tables
– Arrays are also Objects
● Functions are Objects
– Anonymous/lambda functions
– Inner functions, i.e. closures!
● Global object: this, window (browsers)
– All built-in functions can be overridden
● Classes are defined as function
– Members and methods
– Inheritance via prototype
http://www.yuiblog.com/crockford/
Browser programming model
● Single thread per window
– No rendering while executing code
– Can have “Web workers” (more on this later)
● Event queue
– Asynchronous event handling
– Most DOM event callbacks
● Useful: setTimeout/setInterval
– (For animations use requestAnimationFrame)
Browser APIs
● window, document, location, navigator
● AJAX
– Google Maps put this on the map (no pun intended!)
● HTML5
– tons of stuff
● Non-standard / extensions
– Mozilla: OpenWebApps, Audio
– Others?
AJAX
● XMLHttpRequest
● JSON, XML, plain text, etc.
● Same-origin policy
– JSONP work-around
● 2-6 simultaneous connections to a host
● Comet
– Server “pushes” data to browser
– e.g. Long-polling
HTML5
Media
<audio>
<video>
Drag and Drop
History
Canvas2D + WebGL
<canvas>
Web Workers
Server-sent events
Web Storage
Web Sockets
File System
Indexed DB
Web RTC
Fullscreen + Page Visibility
Battery + Sensors
User media (camera)
Really exciting
● HTML5 Audio + Video
● Canvas2D + WebGL
– Hardware-accelerated 3D games
● Web RTC
– Peer-to-peer bi-directional communication
● Device sensors + user media
– Firefox OS exposes even more
● Web Workers
– Better than setTimeout/setInterval
Utility libraries
● JQuery (~32 KB)
– Simplify cross-browser HTML scripting
– CDN: jQuery, Google, MS
– Alternatives: Prototype, Ext.js, Dojo, MooTools, Script.aculo.us
● Lodash/Underscore (~8 KB)
– Utility belt, e.g. Array.reduce()
● Async (~3 KB)
– Simplify asynchronous programming
● Many others...
MVC
● Object-Oriented design pattern
– Ruby-on-Rails, Django, CodeIgniter, etc.
● Essential for single-page web apps
● Backbone (~6 KB)
– Uses events extensively
– Models connect to HTML5 storage or server
– Controller/View objects handle DOM events
– Router handles URLs and History changes
● Tons of other frameworks
– Angular, Ember, Knockout, Dojo, YUI, many others...
http://todomvc.com/
UI frameworks
● JQuery UI
– JQuery Mobile
● Kendo UI (non-free)
– Uses jQuery
– Kendo Mobile
● Wijmo (non-free)
– Built on jQuery + jQuery UI
● Sencha Ext JS (non-free)
– Sencha Touch
Also built on jQuery...
● Easy UI
● Zino UI
● Ignite UI
● jQWidgets
Modules and dependencies
● Modules are good
– Avoid global namespace pollution
– Explicitly specify code dependencies
● No concept of modules in JS
– Coming in future versions
● Current work-arounds:
– AMD
– CommonJS
define(['jquery'], function( $ ){
return {
hideIt: function() {
$('#myDiv').hide();
}
};
});
var $ = require('jquery');
module.exports = {
hideIt: function() {
$('#myDiv').hide();
}
}
● Load-on-demand, with remote loading
● RequireJS (~6 KB)
● Optimizer which concatenates all into
one file
AMD CommonJS
● More natural way of writing a module
● Load everything at the start, locally only
Ideally, use both!
(function(){
// in browser this should be the 'window' object
var global = this;
var myClass = {
...
}
// AMD
if (typeof define !== "undefined" && define !== null && define.amd) {
define(function() {
return myClass;
});
}
// CommonJS
else if (typeof module !== "undefined" && module !== null) {
module.exports = myClass;
}
// Browser
else {
global.myClass = myClass;
}
}());
Building your project...
● SCRIPTs loaded one at a time, unlike CSS
● How to speed it up?
– Minify all scripts
● Uglify, Google Closure, YUI Compressor
– Concatenate all scripts into one file
● RequireJS (AMD), Hem (CommonJS)
● Grunt – a make for Javascript
● Bower – like apt-get for your Javascript packages
● Yeoman = Yo + Grunt + Bower
Back-end scripting
● Mozilla Rhino
● Ringo JS
– Based on Rhino
● Node.js
– This one has the momentum!
Node.js
● Event-driven asynchronous I/O
– One thread for app, one for handling I/O
● V8 Engine from Chrome
● Windows, OS X, Linux
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Worldn');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
http://nodejs.org/
Used by:
● Wall Street Journal
● Microsoft
● eBay
● many more...
Node.js community
● Node Package Manager (like apt-get)
– ~30,000 packages
– Almost all on Github, so easy to contribute
● Notable packages:
– Express JS – MVC framework
– Socket.IO – Bi-directional client-server comms.
– Mongoose – MongoDB client library
– Jade – template language
– Grunt – build tool (remember?)
http://npmjs.org/
Variations + alternatives
● Javascript has many flaws and annoyances
● Next version will fix a lot of things
– But will still take time to become available across
all browsers and devices
● What can we do today?
– CoffeeScript, ClojureScript, TypeScript, Opal
– Dart
– many others...
http://altjs.org/
CoffeeScript
● Released in 2009
● Looks like Ruby and Python
● Great features and shortcuts
– Classical inheritance
– Loops and comprehensions
● Translates 1-on-1 to Javascript
● Hard to debug
– Unless your IDE can use its source maps
● Very popular NPM module
http://coffeescript.org/
Account = (customer, cart) ->
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =>
@customer.purchase @cart
var Account;
Account = function(customer, cart) {
var _this = this;
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click',
function(event) {
return
_this.customer.purchase(_this.cart);
});
};
CoffeeScript Javascript
More runnable examples on http://coffeescript.org/
Dart
● Google released it in 2011
– They hope this will replace Javascript in future
● Class-based OOP language
● Full-stack
– Virtual Machine for running on server
– Compiles to Javascript for browser
● Chromium comes bundled with Dart VM
● IDE and SDK available
● Still not that popular
– Other browser vendors not keen
Dart example
library hi;
import 'dart:html';
main() {
query('#status').text = 'Hi, Dart';
}
<html>
<head>
<title>Hi Dart</title>
</head>
<body>
<h2 id="status">Waiting for Dart to start</h2>
<script type="application/dart" src="hi.dart"></script>
<script
src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/browser/lib/dart.js
"></script>
</body>
</html>
The cutting edge
●
ES.Next (ECMAScript 6?)
– Modules, Classes
– Object.observe(), Proxies
– Maps, Sets
– Usable today with Harmonzir
●
Emscripten (Mozilla)
– Compile LLVM byte-code to Javascript
●
C/C++, anyone?
●
asm.js (Mozilla)
– Highly-optimizable ow-level subset
– Opt-in: use asm
●
Unreal Engine demo: http://www.unrealengine.com/html5/
– Emscripten + asm.js
– Only 2x slower than C++ version
●
Comparable to Java, C#
Staying up-to-date
● DailyJS
– http://dailyjs.com/
● Badass JS
– http://badassjs.com/
● Planet Node
– http://planetnodejs.com/
● Node Up
– http://nodeup.com/
1 of 26

Recommended

Introduction to rails by
Introduction to railsIntroduction to rails
Introduction to railsGo Asgard
433 views19 slides
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus by
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausWomen in Technology Poland
2K views69 slides
Javascript basics by
Javascript basicsJavascript basics
Javascript basicsFalcon2018
15 views4 slides
Node.js for Rubists by
Node.js for RubistsNode.js for Rubists
Node.js for RubistsSagiv Ofek
905 views35 slides
Web assembly with go by
Web assembly with goWeb assembly with go
Web assembly with goWangChow1
286 views16 slides
Autolab Workshop by
Autolab WorkshopAutolab Workshop
Autolab WorkshopMihir Pandya
506 views23 slides

More Related Content

What's hot

브라우저에 날개를 달자 by
브라우저에 날개를 달자브라우저에 날개를 달자
브라우저에 날개를 달자NAVER SHOPPING
574 views15 slides
PHP and node.js Together by
PHP and node.js TogetherPHP and node.js Together
PHP and node.js TogetherChris Tankersley
16.7K views21 slides
About order form improvements by
About order form improvementsAbout order form improvements
About order form improvementsGengo
5K views14 slides
Integrating Node.js with PHP by
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHPLee Boynton
63K views24 slides
Front End Development Automation with Grunt by
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with GruntLadies Who Code
3.3K views36 slides
Angular2 getting started by Stephen Lautier by
Angular2 getting started by Stephen LautierAngular2 getting started by Stephen Lautier
Angular2 getting started by Stephen LautierAndrei Toma
296 views18 slides

What's hot(20)

브라우저에 날개를 달자 by NAVER SHOPPING
브라우저에 날개를 달자브라우저에 날개를 달자
브라우저에 날개를 달자
NAVER SHOPPING574 views
About order form improvements by Gengo
About order form improvementsAbout order form improvements
About order form improvements
Gengo5K views
Integrating Node.js with PHP by Lee Boynton
Integrating Node.js with PHPIntegrating Node.js with PHP
Integrating Node.js with PHP
Lee Boynton63K views
Front End Development Automation with Grunt by Ladies Who Code
Front End Development Automation with GruntFront End Development Automation with Grunt
Front End Development Automation with Grunt
Ladies Who Code3.3K views
Angular2 getting started by Stephen Lautier by Andrei Toma
Angular2 getting started by Stephen LautierAngular2 getting started by Stephen Lautier
Angular2 getting started by Stephen Lautier
Andrei Toma296 views
Running Containerized Node.js Services on AWS Elastic Beanstalk by zupzup.org
Running Containerized Node.js Services on AWS Elastic BeanstalkRunning Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic Beanstalk
zupzup.org478 views
3 Things Everyone Knows About Node JS That You Don't by F5 Buddy
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy443 views
Why ruby by Bill Chea
Why rubyWhy ruby
Why ruby
Bill Chea589 views
Gluecon 2014 - Bringing Node.js to the JVM by Jeremy Whitlock
Gluecon 2014 - Bringing Node.js to the JVMGluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVM
Jeremy Whitlock2.2K views
Going offline with JS (DDD Sydney) by brendankowitz
Going offline with JS (DDD Sydney)Going offline with JS (DDD Sydney)
Going offline with JS (DDD Sydney)
brendankowitz1.4K views
Game Development with Corona SDK and Lua - Lua Workshop 2014 by SergeyLerg
Game Development with Corona SDK and Lua - Lua Workshop 2014Game Development with Corona SDK and Lua - Lua Workshop 2014
Game Development with Corona SDK and Lua - Lua Workshop 2014
SergeyLerg1.1K views
I18nize Scala programs à la gettext by Ngoc Dao
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
Ngoc Dao2K views
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5 by David Voyles
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
David Voyles6.9K views
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js by MongoDB
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.jsThe MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
MongoDB78.7K views

Viewers also liked

Detalle de creacion de "Mi primera base de datos" by
Detalle de creacion de "Mi primera base de datos"Detalle de creacion de "Mi primera base de datos"
Detalle de creacion de "Mi primera base de datos"rmirandaibanez
409 views7 slides
Social Media by
Social MediaSocial Media
Social Mediardsensix
421 views22 slides
El uso de facebook y el trabajo áulico by
El uso de facebook y el trabajo áulicoEl uso de facebook y el trabajo áulico
El uso de facebook y el trabajo áulicoEloísa Toriz
300 views17 slides
Honico portrait 2012 by
Honico portrait 2012Honico portrait 2012
Honico portrait 2012media-in-site
153 views2 slides
Edulcorantes no caloricos by
Edulcorantes no caloricosEdulcorantes no caloricos
Edulcorantes no caloricosIsaac Campuzano
847 views5 slides
Qepa m4 portafolio actividad integradora by
Qepa m4 portafolio actividad integradoraQepa m4 portafolio actividad integradora
Qepa m4 portafolio actividad integradoraQuetzalli De Avila
544 views9 slides

Viewers also liked(20)

Detalle de creacion de "Mi primera base de datos" by rmirandaibanez
Detalle de creacion de "Mi primera base de datos"Detalle de creacion de "Mi primera base de datos"
Detalle de creacion de "Mi primera base de datos"
rmirandaibanez409 views
Social Media by rdsensix
Social MediaSocial Media
Social Media
rdsensix421 views
El uso de facebook y el trabajo áulico by Eloísa Toriz
El uso de facebook y el trabajo áulicoEl uso de facebook y el trabajo áulico
El uso de facebook y el trabajo áulico
Eloísa Toriz300 views
nombres es word art by stiven-918
nombres es word artnombres es word art
nombres es word art
stiven-918496 views
Vuelos cancelados por la huelga del sepla (17 20 febrero) by Iberia
Vuelos cancelados por la huelga del sepla (17 20 febrero)Vuelos cancelados por la huelga del sepla (17 20 febrero)
Vuelos cancelados por la huelga del sepla (17 20 febrero)
Iberia806 views
Al gan ultraviolet photodetectors grown by molecular beam epitaxy on si(111) ... by Kal Tar
Al gan ultraviolet photodetectors grown by molecular beam epitaxy on si(111) ...Al gan ultraviolet photodetectors grown by molecular beam epitaxy on si(111) ...
Al gan ultraviolet photodetectors grown by molecular beam epitaxy on si(111) ...
Kal Tar706 views
La casa del columpio - Capítulo primero (http://lacasadelcolumpio.blogspot.com) by Franklin Díaz Lárez
La casa del columpio - Capítulo primero (http://lacasadelcolumpio.blogspot.com)La casa del columpio - Capítulo primero (http://lacasadelcolumpio.blogspot.com)
La casa del columpio - Capítulo primero (http://lacasadelcolumpio.blogspot.com)
Digital inclusion Case Study For Inverclyde Council's Community Learning and ... by Colin Crook
Digital inclusion Case Study For Inverclyde Council's Community Learning and ...Digital inclusion Case Study For Inverclyde Council's Community Learning and ...
Digital inclusion Case Study For Inverclyde Council's Community Learning and ...
Colin Crook471 views
EMF, What is it, and why should you care? by Shannon Hall,
EMF, What is it, and why should you care?EMF, What is it, and why should you care?
EMF, What is it, and why should you care?
Shannon Hall,912 views
Hermano gabriel taborin RIP by Dome Garces
Hermano gabriel taborin RIPHermano gabriel taborin RIP
Hermano gabriel taborin RIP
Dome Garces213 views
Hidden automation-the-power-of-gel-scripting by Prashank Singh
Hidden automation-the-power-of-gel-scriptingHidden automation-the-power-of-gel-scripting
Hidden automation-the-power-of-gel-scripting
Prashank Singh524 views
Interviu 45 grupo resumido by antonvs
Interviu 45 grupo resumidoInterviu 45 grupo resumido
Interviu 45 grupo resumido
antonvs876 views
6 Awesomely Practical Tips: Making content better for everyone by Whitney Quesenbery
6 Awesomely Practical Tips: Making content better for everyone6 Awesomely Practical Tips: Making content better for everyone
6 Awesomely Practical Tips: Making content better for everyone
Whitney Quesenbery2.4K views
Networking ejecutivo: Importancia del LinkedIn by CAMTIC
Networking ejecutivo: Importancia del LinkedInNetworking ejecutivo: Importancia del LinkedIn
Networking ejecutivo: Importancia del LinkedIn
CAMTIC460 views

Similar to Javascript Update May 2013

Node.js Web Apps @ ebay scale by
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleDmytro Semenov
1.8K views77 slides
Deploying Perl apps on dotCloud by
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
2.5K views37 slides
Lightweight Virtualization with Linux Containers and Docker | YaC 2013 by
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013dotCloud
14.2K views76 slides
Lightweight Virtualization with Linux Containers and Docker I YaC 2013 by
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Docker, Inc.
1.1K views76 slides
Dart the Better JavaScript by
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
1.1K views43 slides
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,... by
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...Mario Heiderich
45.4K views52 slides

Similar to Javascript Update May 2013(20)

Node.js Web Apps @ ebay scale by Dmytro Semenov
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
Dmytro Semenov1.8K views
Deploying Perl apps on dotCloud by daoswald
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
daoswald2.5K views
Lightweight Virtualization with Linux Containers and Docker | YaC 2013 by dotCloud
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
dotCloud14.2K views
Lightweight Virtualization with Linux Containers and Docker I YaC 2013 by Docker, Inc.
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.1.1K views
Dart the Better JavaScript by Jorg Janke
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
Jorg Janke1.1K views
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,... by Mario Heiderich
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
Mario Heiderich45.4K views
Docker and-containers-for-development-and-deployment-scale12x by rkr10
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10112 views
Once upon a time, there were css, js and server-side rendering by Andrea Giannantonio
Once upon a time, there were css, js and server-side renderingOnce upon a time, there were css, js and server-side rendering
Once upon a time, there were css, js and server-side rendering
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo... by Yandex
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Yandex20.1K views
Your First Scala Web Application using Play 2.1 by Matthew Barlocker
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
Matthew Barlocker9.7K views
Geospatial web services using little-known GDAL features and modern Perl midd... by Ari Jolma
Geospatial web services using little-known GDAL features and modern Perl midd...Geospatial web services using little-known GDAL features and modern Perl midd...
Geospatial web services using little-known GDAL features and modern Perl midd...
Ari Jolma165 views
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition by Jérôme Petazzoni
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Jérôme Petazzoni6.5K views
In the DOM, no one will hear you scream by Mario Heiderich
In the DOM, no one will hear you screamIn the DOM, no one will hear you scream
In the DOM, no one will hear you scream
Mario Heiderich33.2K views
Dragoncraft Architectural Overview by jessesanford
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
jessesanford653 views
Docker 0.11 at MaxCDN meetup in Los Angeles by Jérôme Petazzoni
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los Angeles
Jérôme Petazzoni6.1K views

More from Ramesh Nair

solUI Introduction (2019) by
solUI Introduction (2019)solUI Introduction (2019)
solUI Introduction (2019)Ramesh Nair
34 views21 slides
Kickback - incentivizing event attendance through crypto economics by
Kickback - incentivizing event attendance through crypto economicsKickback - incentivizing event attendance through crypto economics
Kickback - incentivizing event attendance through crypto economicsRamesh Nair
407 views22 slides
Introduction to Blockchains by
Introduction to BlockchainsIntroduction to Blockchains
Introduction to BlockchainsRamesh Nair
157 views72 slides
Introduction to PhoneGap by
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapRamesh Nair
3.9K views15 slides
Javascript ES6 generators by
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generatorsRamesh Nair
4.4K views22 slides
Introduction to Dart by
Introduction to DartIntroduction to Dart
Introduction to DartRamesh Nair
2.5K views46 slides

More from Ramesh Nair(7)

solUI Introduction (2019) by Ramesh Nair
solUI Introduction (2019)solUI Introduction (2019)
solUI Introduction (2019)
Ramesh Nair34 views
Kickback - incentivizing event attendance through crypto economics by Ramesh Nair
Kickback - incentivizing event attendance through crypto economicsKickback - incentivizing event attendance through crypto economics
Kickback - incentivizing event attendance through crypto economics
Ramesh Nair407 views
Introduction to Blockchains by Ramesh Nair
Introduction to BlockchainsIntroduction to Blockchains
Introduction to Blockchains
Ramesh Nair157 views
Introduction to PhoneGap by Ramesh Nair
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
Ramesh Nair3.9K views
Javascript ES6 generators by Ramesh Nair
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
Ramesh Nair4.4K views
Introduction to Dart by Ramesh Nair
Introduction to DartIntroduction to Dart
Introduction to Dart
Ramesh Nair2.5K views
ES6 - Next Generation Javascript by Ramesh Nair
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
Ramesh Nair12.3K views

Recently uploaded

Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...ShapeBlue
63 views13 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
82 views62 slides
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
83 views15 slides
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
46 views15 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
136 views25 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
50 views23 slides

Recently uploaded(20)

Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue63 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue82 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue83 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue46 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue50 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue119 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue102 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays40 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue111 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue56 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue46 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue88 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue54 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc77 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue131 views

Javascript Update May 2013

  • 1. The Javascript Update Ramesh Nair ram@hiddentao.com http://twitter.com/hiddentao Where Javascript is at - May 2013
  • 2. What this talk will cover ● Javascript history ● Language overview ● Browser goodies ● Front-end ecosystem ● Back-end: Node.js ● Variations and alternatives, e.g. CoffeeScript ● The cutting edge – future stuff ● How to stay up-to-date
  • 3. Evolution ● Created in 1995 at Netscape ● Mocha → LiveScript → JavaScript ● Accepted by ECMA by 1997 – ECMAScript is official standard name – Javascript = JScript (Internet Explorer) ● v3 (JS 1.5) set the standard ● ECMA TC39 working on ES.next, Harmony
  • 4. Language overview ● Built-in types: Boolean, Number, String, null, undefined – Strings are UTF-16 ● Dynamically typed ● Objects work as hash tables – Arrays are also Objects ● Functions are Objects – Anonymous/lambda functions – Inner functions, i.e. closures! ● Global object: this, window (browsers) – All built-in functions can be overridden ● Classes are defined as function – Members and methods – Inheritance via prototype http://www.yuiblog.com/crockford/
  • 5. Browser programming model ● Single thread per window – No rendering while executing code – Can have “Web workers” (more on this later) ● Event queue – Asynchronous event handling – Most DOM event callbacks ● Useful: setTimeout/setInterval – (For animations use requestAnimationFrame)
  • 6. Browser APIs ● window, document, location, navigator ● AJAX – Google Maps put this on the map (no pun intended!) ● HTML5 – tons of stuff ● Non-standard / extensions – Mozilla: OpenWebApps, Audio – Others?
  • 7. AJAX ● XMLHttpRequest ● JSON, XML, plain text, etc. ● Same-origin policy – JSONP work-around ● 2-6 simultaneous connections to a host ● Comet – Server “pushes” data to browser – e.g. Long-polling
  • 8. HTML5 Media <audio> <video> Drag and Drop History Canvas2D + WebGL <canvas> Web Workers Server-sent events Web Storage Web Sockets File System Indexed DB Web RTC Fullscreen + Page Visibility Battery + Sensors User media (camera)
  • 9. Really exciting ● HTML5 Audio + Video ● Canvas2D + WebGL – Hardware-accelerated 3D games ● Web RTC – Peer-to-peer bi-directional communication ● Device sensors + user media – Firefox OS exposes even more ● Web Workers – Better than setTimeout/setInterval
  • 10. Utility libraries ● JQuery (~32 KB) – Simplify cross-browser HTML scripting – CDN: jQuery, Google, MS – Alternatives: Prototype, Ext.js, Dojo, MooTools, Script.aculo.us ● Lodash/Underscore (~8 KB) – Utility belt, e.g. Array.reduce() ● Async (~3 KB) – Simplify asynchronous programming ● Many others...
  • 11. MVC ● Object-Oriented design pattern – Ruby-on-Rails, Django, CodeIgniter, etc. ● Essential for single-page web apps ● Backbone (~6 KB) – Uses events extensively – Models connect to HTML5 storage or server – Controller/View objects handle DOM events – Router handles URLs and History changes ● Tons of other frameworks – Angular, Ember, Knockout, Dojo, YUI, many others... http://todomvc.com/
  • 12. UI frameworks ● JQuery UI – JQuery Mobile ● Kendo UI (non-free) – Uses jQuery – Kendo Mobile ● Wijmo (non-free) – Built on jQuery + jQuery UI ● Sencha Ext JS (non-free) – Sencha Touch Also built on jQuery... ● Easy UI ● Zino UI ● Ignite UI ● jQWidgets
  • 13. Modules and dependencies ● Modules are good – Avoid global namespace pollution – Explicitly specify code dependencies ● No concept of modules in JS – Coming in future versions ● Current work-arounds: – AMD – CommonJS
  • 14. define(['jquery'], function( $ ){ return { hideIt: function() { $('#myDiv').hide(); } }; }); var $ = require('jquery'); module.exports = { hideIt: function() { $('#myDiv').hide(); } } ● Load-on-demand, with remote loading ● RequireJS (~6 KB) ● Optimizer which concatenates all into one file AMD CommonJS ● More natural way of writing a module ● Load everything at the start, locally only
  • 15. Ideally, use both! (function(){ // in browser this should be the 'window' object var global = this; var myClass = { ... } // AMD if (typeof define !== "undefined" && define !== null && define.amd) { define(function() { return myClass; }); } // CommonJS else if (typeof module !== "undefined" && module !== null) { module.exports = myClass; } // Browser else { global.myClass = myClass; } }());
  • 16. Building your project... ● SCRIPTs loaded one at a time, unlike CSS ● How to speed it up? – Minify all scripts ● Uglify, Google Closure, YUI Compressor – Concatenate all scripts into one file ● RequireJS (AMD), Hem (CommonJS) ● Grunt – a make for Javascript ● Bower – like apt-get for your Javascript packages ● Yeoman = Yo + Grunt + Bower
  • 17. Back-end scripting ● Mozilla Rhino ● Ringo JS – Based on Rhino ● Node.js – This one has the momentum!
  • 18. Node.js ● Event-driven asynchronous I/O – One thread for app, one for handling I/O ● V8 Engine from Chrome ● Windows, OS X, Linux var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); http://nodejs.org/ Used by: ● Wall Street Journal ● Microsoft ● eBay ● many more...
  • 19. Node.js community ● Node Package Manager (like apt-get) – ~30,000 packages – Almost all on Github, so easy to contribute ● Notable packages: – Express JS – MVC framework – Socket.IO – Bi-directional client-server comms. – Mongoose – MongoDB client library – Jade – template language – Grunt – build tool (remember?) http://npmjs.org/
  • 20. Variations + alternatives ● Javascript has many flaws and annoyances ● Next version will fix a lot of things – But will still take time to become available across all browsers and devices ● What can we do today? – CoffeeScript, ClojureScript, TypeScript, Opal – Dart – many others... http://altjs.org/
  • 21. CoffeeScript ● Released in 2009 ● Looks like Ruby and Python ● Great features and shortcuts – Classical inheritance – Loops and comprehensions ● Translates 1-on-1 to Javascript ● Hard to debug – Unless your IDE can use its source maps ● Very popular NPM module http://coffeescript.org/
  • 22. Account = (customer, cart) -> @customer = customer @cart = cart $('.shopping_cart').bind 'click', (event) => @customer.purchase @cart var Account; Account = function(customer, cart) { var _this = this; this.customer = customer; this.cart = cart; return $('.shopping_cart').bind('click', function(event) { return _this.customer.purchase(_this.cart); }); }; CoffeeScript Javascript More runnable examples on http://coffeescript.org/
  • 23. Dart ● Google released it in 2011 – They hope this will replace Javascript in future ● Class-based OOP language ● Full-stack – Virtual Machine for running on server – Compiles to Javascript for browser ● Chromium comes bundled with Dart VM ● IDE and SDK available ● Still not that popular – Other browser vendors not keen
  • 24. Dart example library hi; import 'dart:html'; main() { query('#status').text = 'Hi, Dart'; } <html> <head> <title>Hi Dart</title> </head> <body> <h2 id="status">Waiting for Dart to start</h2> <script type="application/dart" src="hi.dart"></script> <script src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/browser/lib/dart.js "></script> </body> </html>
  • 25. The cutting edge ● ES.Next (ECMAScript 6?) – Modules, Classes – Object.observe(), Proxies – Maps, Sets – Usable today with Harmonzir ● Emscripten (Mozilla) – Compile LLVM byte-code to Javascript ● C/C++, anyone? ● asm.js (Mozilla) – Highly-optimizable ow-level subset – Opt-in: use asm ● Unreal Engine demo: http://www.unrealengine.com/html5/ – Emscripten + asm.js – Only 2x slower than C++ version ● Comparable to Java, C#
  • 26. Staying up-to-date ● DailyJS – http://dailyjs.com/ ● Badass JS – http://badassjs.com/ ● Planet Node – http://planetnodejs.com/ ● Node Up – http://nodeup.com/

Editor's Notes

  1. Such a big topic so this is really a “crash” update. Ask if you want more detail about something.
  2. http://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript Brendan Eich (Mozilla) created it. Name similar to Java for marketing reasons. ECMA = European Computer Manufacturers Association Javascript is an implementation of ECMAScript, as is Actionscript (Flash). Called ECMAScript to avoid Sun licensing fees Jscript = Microsoft not wanting to pay licensing fees to Sun for &apos;Java&apos; name. ECMA TC39 = all major browser vendors. ES.next = next version of ECMAScript, probably v6 Harmony = stuff for future versions (beyond ES.next)
  3. http://www.crockford.com/javascript/survey.html http://www.yuiblog.com/crockford/
  4. http://javascript.info/tutorial/events-and-timing-depth http://dev.opera.com/articles/view/timing-and-synchronization-in-javascript/ http://www.nczonline.net/blog/2011/05/03/better-javascript-animations-with-requestanimationframe/ https://gist.github.com/paulirish/1579671 Single thread – so no rendering while running JS. Web workers which are essentially in sub processes. Event queue – a list of functions to execute in order. DOM events get placed here as do setTimeout events, etc. SetTimeout/setInterval very useful for splitting up long-running tasks. But they only tell you when the callback is queued, not when it&apos;s executed. For animations best to use requestAnimationFrame(), now supported as a custom extension in all major browsers. Some events are synchronous – e.g. .focus() - and are handled immediately. Model stuff – e.g. alert() - is also synchronous and pauses everything else.
  5. AJAX has been the bread-and-butter of responsive web apps over the past decade. HTML5 brings a ton of stuff to the table. Vendors (esp. Mozilla) are always pushing for improvements. Mozilla are very focussed on Firefox OS. OpenWebApps – to install and manage open web apps Audio API extensions – to be able to get audio metadata and raw framebuffer data as well as modify it
  6. http://stackoverflow.com/questions/561046/how-many-concurrent-ajax-xmlhttprequest-requests-are-allowed-in-popular-browse https://developer.mozilla.org/en/docs/DOM/XMLHttpRequest http://en.wikipedia.org/wiki/Comet_(programming ) Asynchronous-Javascript-and-XML Talk to server in the background. Looks the same as any other HTTP request. XMLHttpRequest designed by MS, now being standardized. Can also be used for FTP and File URLs. JSON is probably more commonly used datatype as it uses less bandwidth and is easier to manipulte in JS. Same-origin policy: the script must make AJAX call to server from the script came. Subdomains don&apos;t count. JSONP works around this by calling a pre-specified function of yours with the data. Generally allowed between 2 to 6 simultaneous AJAX connections to one host. Comet – umbrella term for techniques used to push data from server to browser, e.g. long-polling.
  7. http://www.netmagazine.com/features/developer-s-guide-html5-apis http://platform.html5.org/ These are the main ones, some of which are finalised. Most are still undergoing discussions. Almost all the above are supported in all browsers. Desktop browser support better than mobile browser support.
  8. Still no agreement on royalty-free video codec. Opus recently standardized as the royalty-free audio codec. Web workers can&apos;t access the DOM Web RTC – peer-to-peer chat, gaming, sharing, etc. More efficient
  9. http://www.jscripters.com/popular-jquery-alternatives/ You should be using jQuery or some other library which hides browser differences. Jquery is available on CDNs – this can reduce load time for your site. These are the main jQuery alternatives in use, though I think jQuery is the most popular by far. Lodash and Underscore are utility belts. e.g. useful Array methods, Object methods. Browsers with newer JS versions have the standard built-in equivalents. But if you&apos;re not sure just use on of these. They are both API compatible (Lodash has better performance though) Async just makes asynchronous programming less painful. Last two are useful for back-end JS too. I&apos;ve included .min.gz sizes because whenever you choose to use a library or framework in the browser it&apos;s important to know how much of an impact this will have on bandwidth and page load speed. Too many to mention, but these are the ones I always use.
  10. MVC = Model View Controller Widely implemented in nearly all web languages in the form of MVC frameworks. Almost essential for single-page web apps because there&apos;s so much JS logic involved. Backbone is one of the most lightweight and widely used MVC frameworks in JS. Lots of extensions and plugins available. Addy Osmani&apos;s site provides thorough examples of each one.
  11. UI frameworks mainly provide widgets and rich visual objects, e.g. graphing, datagrid, etc. as well as way to easily get data in and out of them. JQuery Mobile scales to all form factors whereas the other mobile UI fwks tend to be mobile-only focussed.
  12. http://addyosmani.com/writing-modular-js/ In WP or Drupal you can&apos;t name your functions the same as core ones! Important to decouple application by writing re-usable modules. Have classes but each file would ideally be a module on its own
  13. RequireJS recommended for browser development because it doesn&apos;t require builds during development (edit → save → refresh) and allows for remote loading, yet has an optimization process for producing a single file at the end. Also optimizes CSS files. CommonJS used in node.js back-end.
  14. You tend to see this in many JS libraries to cater for both AMD and CommonJS use-case. Libraries which are designed for both front- and back-end JS will most likely have this in. You should have this in your code to make it easy as possible for others to re-use without modification. The last condition caters for raw usage – will usually only be meaningful if running browser. I haven&apos;t included stuff like noConflict(). JQuery uses this to allow 2 different versions of the lib at the same time.
  15. Most new libraries nowadays use uglify as its the most efficient in terms of compressed size Yo (Yeoman) creates scaffolding for you
  16. Event-driven single-threaded model https://github.com/joyent/node/wiki/Projects%2C-Applications%2C-and-Companies-Using-Node
  17. Anyone can publish a package to NPM very easily from their shell. Github presence makes it easy to work out which packages are the most popular and which developers are worth following. All core node.js work happens on Github too.
  18. http://altjs.org/ Has a comprehensive listing of JS improvments and alternatives TypeScript is by Microsoft. ClojureScript lets your write Clojure and target JS.
  19. http://carbonfive.github.io/why-coffeescript/
  20. No semicolons. Operator to bind function to &apos;this&apos;. Shorthand for &apos;this&apos;.
  21. Chromium can run Dart code natively. Because Dart is proprietary other browser vendors are not keen.
  22. We load the dart2js compiler in order to translate the Dart file to JS on the fly. Note the application/dart MIME type.
  23. http://addyosmani.com/blog/a-few-new-things-coming-to-javascript/ ES.next usable today using Harmonizr ( https://github.com/jdiamond/harmonizr ) LLVM = &apos;Low-level virtual machine”. Compiler infrastructure for C/C++ which has now front-ends for many other languages Asm.js us usable today on all browsers and devices. Other browser vendors already interested. http://ejohn.org/blog/asmjs-javascript-compile-target/ Epic + Mozilla released Unreal Engine 3 demo using asm.js: http://www.extremetech.com/gaming/154994-epic-mozilla-release-unreal-engine-3-html5-demo-to-the-public-and-its-awesome Unreal Engine ported to HTML5 + WebGL + JS in just 4 days! Performance comparable to Java, C#.