JavaScript, past 'til present Simon Skoczylas Senior Software DeveloperMaterna GmbH
Java, JavaScript
Web, Frontend
Agenda Motivation JavaScript usage ECMAScript 6 Node.js JavaScript? Mostly kown within web browsers Introduced by Netscape, JavaScript vs applets More lightweight as applets "dynamic content" Early versions cruel and used for blinking text and pop-ups ... Script kiddies, bad repute in web browsers Frist revolution with upcoming AJAX Facts Since 1995 Mocha → LiveScript → JavaScript On client- & server-side from the beginningNetscape Navigator Netscape Enterprise Server Since 1997 part of Ecma International → ECMAScriptECMAScript 1 (1997) ECMAScript 2 (1998) ECMAScript 3 (1999) ECMAScript 4 (the incomplete) ECMAScript 5 (2009) ECMAScript 6 (2015)ECMAScript 7 (work in progress) History "JavaScript" vs ECMAScript Brendan Eich, Netscape, ~10 Days JavaScript!!! JavaScript vs ECMAScriptWeb browser vs standard JavaScript ~ ECMAScript 3/5/(6) + DOM API window, document, ... JavaScript Versions (John Resig, 2008)Nashorn (Java), Adobe ExtendedScript (Photoshop etc.), JScript .NET, ... ECMAScript standard JavaScript is a dialekt mostly for the web browser Versionnumber hard to determinate, ECMAScript vs JavaScript JavaScript Versions (John Resig, 2008) IE 6-7 support JScript 5 (which is equivalent to ECMAScript 3, JavaScript 1.5) IE 8 supports JScript 6 (which is equivalent to ECMAScript 3, JavaScript 1.5 – more bug fixes over JScript 5) Firefox 1.0 supports JavaScript 1.5 (ECMAScript 3 equivalent) Firefox 1.5 supports JavaScript 1.6 (1.5 + Array Extras + E4X + misc.) Firefox 2.0 supports JavaScript 1.7 (1.6 + Generator + Iterators + let + misc.) Firefox 3.0 supports JavaScript 1.8 (1.7 + Generator Expressions + Expression Closures + misc.) The next version of Firefox will support JavaScript 1.9 (1.8 + To be determined) Opera supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc. Safari supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc. ECMAScript As JavaScript one of the most important web technologies Interpreted at run-time Prototype-based Supports different programming paradigmsobject-orientated (prototyps) imperativ / procedural functional Not typed at development time, but at run-timeBut: TypeScript (Microsoft, 2012) Language Trends on GitHub (08.2015) TIOBE Index (09.2015) TIOBE Niederlande TIOBE ist umstritten The Dawn Of Enterprise JavaScript JavaScript Finds Its Place In Enterprise Software Development Adoption of JavaScript — and the Node.js runtime environment in particular — sets the stage for the biggest shift in enterprise application development in more than a decade
Currently Java or .NET Nobody wants JavaScript?! Bad for business Wal-Mart no downtime at Black-Friday! Node.js! Usage of JavaScript Where JavaScript is currently in use? Frontend, Single-Page-Applications, Backend, Isomorphic Maybe not for Mission Control Hardware, device drivers, etc. Frontend Web browser At the beginning in use for "dynamic" content with out server connection AJAX brought the possibility to access data from server (2005) Easy to use because of JQuery (2006) Three milestones for JavaScript Blinking text and pop-ups AJAX for auto-complete jQuery + Sizzle for better DOM handling Single-Page-Apps Business-Logic inside the web browserFirst request loads the whole logic into the client Content reloading possible AngularJS by Google (2009)Often in use as MEAN-Stack M ongoDBE xpressJSA gularJSN odeJS Beside AngularJS also existing EmberJS, Meteor Speed like Desktop-Appslications? AngularJS MVC (MVVM, Model-View-ViewModel) Backend NodeJS uses V8, before NodeJS used Mozilla SpiderMonkey (C) Mozilla Rhino (Java) MongoDB (NoSQL), Apache CouchDB, ... Synergy effects At the moment strict divided beweet client and server + database Allows developers to build client, server and database BeforeFront-end vs back-end JavaScript with jQuery at the front-end Java with Tomcat, Struts and Tiles at the back-end AfterJavaScript at front-end and back-end (with NodeJS and ReactJS) Possibility to load balance between front-end and back-end No context switch between languages Identical API to generate HTML for the Front-end and back-end Up-to-date: 5.August.2015 Goal was to speed up netflix.com Isomorphic JavaScript Currently hard gap between client, server and database One developer can rule them all What's new in ECMAScript 6 ECMAScript 6 currently not interessting for the front-end ECMAScript 5 changes are a bit small Strict mode (enables some features) Getters and setter (get=function) Arrays (map, filter, every), Object (create) JSON Variable scope Currently (var) global object (e.g. window), or function Now: let
function doSomethingECMA5() {
var a = ['apple', 'banana'];
for (var i = 0; i < a.length; i++) {
console.log(i, a[i]);
}
console.log(i, a[i]); // undefined, weil [0, 1]
}
function doSomethingECMA6() {
var a = ['apple', 'banana'];
for (let i = 0; i < a.length; i++) {
console.log(i, a[i]);
}
console.log(i, a[i]); // Nicht möglich
}
Constants Currenly only by convention → UPPER CASE Or with object properties
const MAX_COUNT = 5;
console.log(MAX_COUNT); // 5
MAX_COUNT = 6; // use strict = Error
console.log(MAX_COUNT);
String New functions startsWith, endsWith, includes
console.log('hello'.startsWith('hell')); // true
console.log('hello'.endsWith('hell')); // false
console.log('hello'.includes('ell')); // true
Before realized with JQuery Arrow functions
var quadrat = x => x*x;
var result = quadrat(5);
console.log(result); // 25
var addition = (x,y) => x+y;
var result = addition(5, 6);
console.log(result); // 11
() => { };
x => { };
(x, y) => { };
Spread operator Not well supported at the moment
function apple(a, b) {
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
apple('eins', 'zwei', 'drei');
function banana(a, b, ...c) {
c.forEach(function(element) {
console.log(element);
});
}
banana('eins', 'zwei', 'drei');
Default parameter values Not well supported at the moment
function tomato(a, b, c = 'three') {
console.log(a, b, c);
}
tomato('one', 'two'); // one, two, three
Iterators Not well spoorted at the moment
var bands = ['Metallica', 'Queen', 'The Police', 'The Beatles'];
var iterator = bands.values();
iterator.next();
Generators
function* counter() {
yield 1;
yield 2;
}
var someCounter = counter();
var result = someCounter.next();
console.log(result); // { value: 1, done: false }
result = someCounter.next();
console.log(result); // { value: 2, done: false }
result = someCounter.next();
console.log(result); // { value: undefined, done: true }
Modules
export function say() {
return 'hello world';
}
import {say} from 'export';
console.log(say());
Classes
class Person {
constructor(firstname, lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
toString() {
return this.firstname + ' ' + this.lastname;
}
}
var max = new Person('Max', 'Schmidt');
console.log(max.toString()); // Max Schmidt
Classes
class Employee extends Person {
constructor(firstname, lastname, id) {
super(fristname, lastname);
this.id = id;
}
toString() {
return this.id + ': ' + this.firstname + ' ' + this.lastname;
}
}
var anton = new Employee('Anton', 'Mayer', 1);
console.log(anton.toString()); // 1: Anton Mayer
Facts JavaScript for the server V8 by Google, written in C Non blocking I/O Event-driven Single-Thread (actually) nodejs.org Linux, MacOS, Windows, SunOS, ARM32bit & 64bit ARM6, ARM7, ARM8 As of late 4.0.0, before 0.x.y Long Term Support (LTS)NodeJS + io.js merged again MacOS only 64 bit NPM Node Package Manager ~183.000 Module at npmjs.com package.json describes the project Able to load libraries on demand Private NPM! Default modules Assert (similar to JUnit) Addons (C/C++) Buffer Child Process Cluster Console Crypto Debugger (Remote) DNS Errors Events File System HTTP / HTTPS Modules net OS Path process punycode (Encode, Decode) Query String Readline Stream StringDecoder Timers (setTimeout, etc.) TLS (SSL) UDP / Datagram Sockets URL util VM Zlib ExpressJS "Fast, unopinionated, minimalist web framework for Node.js" Most kown web framework for NodeJS Acts as middleware Templates (Jade , Handlebars, Hogan) CSS Preprocessor (LESS, Stylus, Compass, SASS) expressjs.com Legal information Stock images taken from https://pixabay.com/en/light-bulb-lightbulb-light-bulb-1246043/ https://pixabay.com/en/thanks-word-letters-scrabble-1804597/ https://pixabay.com/en/space-shuttle-lift-off-liftoff-nasa-992/ https://unsplash.com/photos/hzgs56Ze49s https://pixabay.com/en/construction-site-build-1510561/ https://unsplash.com/photos/B6yDtYs2IgY https://pixabay.com/en/lost-places-office-broken-1730892/ https://pixabay.com/en/gardening-tools-old-used-worn-1478547/