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
– 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/
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)
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)
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
• 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/
} }; }); 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
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
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 World\n'); }).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...
• 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/
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/
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