Javascript sucks
2014 perspective
JavaScript:
The World's
Most
Misunderstood
Programming
Language
One Step Back:
How Compilation Works
infer types
function compiledCalculation() {
var x = f()|0; // x is a 32-bit value
var y = g()|0; // so is y
return (x+y)|0; // 32-bit addition, no type or overflow
checks
}
typed arrays
var MEM8 = new Uint8Array(1024*1024);
var MEM32 = new Uint32Array(MEM8.buffer); // alias
MEM8's data function
compiledMemoryAccess(x) {
MEM8[x] = MEM8[x+10]; // read from x+10, write to x
MEM32[(x+16)>>2] = 100;
}
Strlen example
function strlen(ptr) { // calculate length of C
string ptr = ptr|0;
var curr = 0;
curr = ptr;
while (MEM8[curr]|0 != 0) {
curr = (curr + 1)|0;
}
return (curr - ptr)|0;
}
 http://kripken.github.io/boon/boon.html
class RaceCar extends Car { //inheritance
constructor(make, topSpeed) {
super(make); //call the parent constructor with super
this.topSpeed = topSpeed;
}
goFast(){
this.currentSpeed = this.topSpeed;
}
class Car {
constructor(make) { //constructors!
this.make = make;
this.currentSpeed = 25;
}
printCurrentSpeed(){
console.log(this.make + ' is going ' + this.currentSpeed
+ ' mph.');
}
}
let stang = new RaceCar('Mustang', 150);
stang.printCurrentSpeed();
stang.goFast();
stang.printCurrentSpeed();
function Car() {
var self = this; //locally assign this that can be closed over
self.speed = 0;
setInterval(function goFaster() {
//this has a different scope, but we can use the self variable to
reference the parent "this"
self.speed += 5;
console.log('now going: ' + self.speed);
}, 1000);
}
var car = new Car();
function Car() { //Note, we could use the new Class feature
in ES6 instead
this.speed = 0;
setInterval(() => {
this.speed += 5; //this is from Car
console.log
console.log('now going: ' + this.speed);
}, 1000);
}
<module>
import $ from 'lib/jquery';
var x = 123;
// The current scope is not global
console.log('$' in window); // false
console.log('x' in window); // false
// `this` still refers to the global object
console.log(this === window); // true
</module>
var num = 0; //globally scoped
for (let i = 0; i < 10; i++) { //i is block scoped
num += i;
console.log('value of i in block: ' + i);
}
console.log('value of i out of block: ' + i);
Where are we now?
 https://kangax.github.io/compat-table/es6/
Any application that can be
written in JavaScript, will
eventually be written in
JavaScript.
2014 perspective
Thank you

Wcbpijwbpij new

  • 2.
  • 3.
  • 19.
    One Step Back: HowCompilation Works
  • 20.
    infer types function compiledCalculation(){ var x = f()|0; // x is a 32-bit value var y = g()|0; // so is y return (x+y)|0; // 32-bit addition, no type or overflow checks }
  • 21.
    typed arrays var MEM8= new Uint8Array(1024*1024); var MEM32 = new Uint32Array(MEM8.buffer); // alias MEM8's data function compiledMemoryAccess(x) { MEM8[x] = MEM8[x+10]; // read from x+10, write to x MEM32[(x+16)>>2] = 100; }
  • 22.
    Strlen example function strlen(ptr){ // calculate length of C string ptr = ptr|0; var curr = 0; curr = ptr; while (MEM8[curr]|0 != 0) { curr = (curr + 1)|0; } return (curr - ptr)|0; }
  • 23.
  • 26.
    class RaceCar extendsCar { //inheritance constructor(make, topSpeed) { super(make); //call the parent constructor with super this.topSpeed = topSpeed; } goFast(){ this.currentSpeed = this.topSpeed; }
  • 27.
    class Car { constructor(make){ //constructors! this.make = make; this.currentSpeed = 25; } printCurrentSpeed(){ console.log(this.make + ' is going ' + this.currentSpeed + ' mph.'); } }
  • 28.
    let stang =new RaceCar('Mustang', 150); stang.printCurrentSpeed(); stang.goFast(); stang.printCurrentSpeed();
  • 30.
    function Car() { varself = this; //locally assign this that can be closed over self.speed = 0; setInterval(function goFaster() { //this has a different scope, but we can use the self variable to reference the parent "this" self.speed += 5; console.log('now going: ' + self.speed); }, 1000); } var car = new Car();
  • 31.
    function Car() {//Note, we could use the new Class feature in ES6 instead this.speed = 0; setInterval(() => { this.speed += 5; //this is from Car console.log console.log('now going: ' + this.speed); }, 1000); }
  • 33.
    <module> import $ from'lib/jquery'; var x = 123; // The current scope is not global console.log('$' in window); // false console.log('x' in window); // false // `this` still refers to the global object console.log(this === window); // true </module>
  • 35.
    var num =0; //globally scoped for (let i = 0; i < 10; i++) { //i is block scoped num += i; console.log('value of i in block: ' + i); } console.log('value of i out of block: ' + i);
  • 37.
    Where are wenow?  https://kangax.github.io/compat-table/es6/
  • 38.
    Any application thatcan be written in JavaScript, will eventually be written in JavaScript. 2014 perspective
  • 39.

Editor's Notes

  • #2 2001
  • #4 crokford
  • #5 The Name
  • #6 Lisp in C's Clothing
  • #7 Typecasting
  • #8 Moving Target
  • #9 Design Errors
  • #10 Lousy Implementations
  • #11 Bad Books
  • #12 Coding horror stated on 2007 state 2012 – will the future be all javascript? 2012 – tool sfor server sode (Rhino, nodeJS etc) start to implement server side in javascript
  • #15 from my perspective, a framework does several things: it makes it easier to work with complex technologies it ties together a bunch of discrete objects/components into something more useful it forces the team (or just me) to implement code in a way that promotes consistent coding, fewer bugs, and more flexible applications everyone can easily test and debug the code, even code that they didn't write
  • #16 Even word press did it. The industry standard is not to use plugins!
  • #18 Then google made this
  • #21 |0 casts to 32bit integer
  • #22 We can get an array and use it as memory
  • #25 Harmony – ECMAScript 6 and new javascript Released in mid 2015? ES 2015
  • #31 Arrow functions
  • #34 Modules
  • #36 Block scoping let is scoped to the nearest enclosing block
  • #37 Block scoping
  • #39 Promise
  • #43  Links http://www.wintellect.com/blogs/nstieglitz/5-great-features-in-es6-harmony