@PhoenixHawk • 1995 - First shipped as LiveScript in Netscape 2 • A bit later renamed to JavaScript • 1996 – Used server-side in Netscape Enterprise Server • 1997 – Standardized as ECMAScript • Late 90ies to mid 20ies (DHTML-Era) • Considered ‚evil‘ • Late 20ies: Renaissance with AJAX & Node.js
P.R. Gingter @PhoenixHawk • Mixing of concerns • No clear separation of functionality or purpose • Variables/functions added into global scope • Potential for duplicate function names • Not modular • Not easy to maintain • No sense of a “container”
var date = new Date(); return date.getMilliseconds(); } Variable lost after function returns EKON 16 - November 2012 Sebastian P.R. Gingter @PhoenixHawk
var date = new Date(); //nested function return function () { return date.getMilliseconds(); }; } Variable stays around even after function returns EKON 16 - November 2012 Sebastian P.R. Gingter @PhoenixHawk
All members are available • Best suited for data var calc = { tempValue: 1, add: function(x, y){ return x + y; } }; EKON 16 - November 2012 Sebastian P.R. Gingter @PhoenixHawk
this.eqCtl = document.getElementById(eq); }; Calculator.prototype = { add: function (x, y) { var val = x + y; this.eqCtl.innerHTML = val; } }; var calc = new Calculator('eqCtl'); calc.add(2,2); EKON 16 - November 2012 Sebastian P.R. Gingter @PhoenixHawk
var eqCtl = document.getElementById(eq), doAdd = function(x,y) { var val = x + y; eqCtl.innerHTML = val; }; return { add: doAdd }; //Expose public member }('eqCtl'); calculator.add(2,2); EKON 16 - November 2012 Sebastian P.R. Gingter @PhoenixHawk