not your mother's javascript

48
Tuesday, September 28, 2010

Upload: schneideratjancona

Post on 17-May-2015

4.705 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Not your mother's JavaScript

Tuesday, September 28, 2010

Page 2: Not your mother's JavaScript

Not your mother’s JavaScript

Tobias Schneider, @tobeytailor - uxebuSep 26 2010, jsconf.eu

Tuesday, September 28, 2010

Page 3: Not your mother's JavaScript

@tobeytailorMunich based web worker

Born as a natural coder in the Black ForrestJavaScript hacker for ~8 years now

Pushing limits for uxebu since August 2010

5 GitHub projects, 1626 watchers, 1143 followers3 bad jokes

Tuesday, September 28, 2010

Page 4: Not your mother's JavaScript

So you’re a hacker, but why JavaScript?

Small, fast and widely misunderstoodMost flexible language of the world

It’s open & almost everywhereHack driven enhanced

You can haz jsconf

It isn’t perfect, still has lots of limits and constrains...

Tuesday, September 28, 2010

Page 5: Not your mother's JavaScript

Constraints boost creativity“If you don't have the right equipment for the job, you just have to make it yourself.” (MacGyver)

Tuesday, September 28, 2010

Page 6: Not your mother's JavaScript

Hack driven enhancementThe evolution of JavaScript is a history full of workarounds.

Tuesday, September 28, 2010

Page 7: Not your mother's JavaScript

First, there’s a limitation

Tuesday, September 28, 2010

Page 8: Not your mother's JavaScript

Then there’s a hack

Tuesday, September 28, 2010

Page 9: Not your mother's JavaScript

The interwebs likes it?

Tuesday, September 28, 2010

Page 10: Not your mother's JavaScript

Then it gets a buzzy name and becomes a

standard

Tuesday, September 28, 2010

Page 11: Not your mother's JavaScript

Do you remember...AJAX in 2001?

Canvas before 2004?Cross Domain Ajax 2010?

Tuesday, September 28, 2010

Page 12: Not your mother's JavaScript

AJAX 2001Requirement:

Requesting the server without reloading the whole page again & again & again...

Tuesday, September 28, 2010

Page 13: Not your mother's JavaScript

AJAX 2001Requirement:

Requesting the server without reloading the whole page again & again & again...

Why?Loading data async

Tuesday, September 28, 2010

Page 14: Not your mother's JavaScript

AJAX 2001Requirement:

Requesting the server without reloading the whole page again & again & again...

Why?Loading data async

HackiFrame fun

Tuesday, September 28, 2010

Page 15: Not your mother's JavaScript

AJAX 2001Requirement:

Requesting the server without reloading the whole page again & again & again...

Why?Loading data async

HackiFrame fun

Specification todayXHR

Tuesday, September 28, 2010

Page 16: Not your mother's JavaScript

Canvas 2003Requirement:

Drawing pictures in the browser

Tuesday, September 28, 2010

Page 17: Not your mother's JavaScript

Canvas 2003Requirement:

Drawing pictures in the browser

Why?LASERS!!!

Tuesday, September 28, 2010

Page 18: Not your mother's JavaScript

HackTons of IMG’s in your DOM rendered with IM

Canvas 2003Requirement:

Drawing pictures in the browser

Why?LASERS!!!

Tuesday, September 28, 2010

Page 19: Not your mother's JavaScript

Canvas 2003Requirement:

Drawing pictures in the browser

Why?LASERS!!!

HackTons of IMG’s in your DOM rendered with IM

Specification todayCanvas API (ExCanvas!)

Tuesday, September 28, 2010

Page 20: Not your mother's JavaScript

Cross Domain AjaxRequirement:

Having a script from domain X loading data from Y

Tuesday, September 28, 2010

Page 21: Not your mother's JavaScript

Cross Domain AjaxRequirement:

Having a script from domain X loading data from Y

Why?e.g. Pulling public web services

Tuesday, September 28, 2010

Page 22: Not your mother's JavaScript

Cross Domain AjaxRequirement:

Having a script from domain X loading data from Y

Why?e.g. Pulling public web services

HackJSONP

Tuesday, September 28, 2010

Page 23: Not your mother's JavaScript

Cross Domain AjaxRequirement:

Having a script from domain X loading data from Y

Why?e.g. Pulling public web services

HackJSONP!

Tuesday, September 28, 2010

Page 24: Not your mother's JavaScript

Cross Domain AjaxRequirement:

Having a script from domain X loading data from Y

Why?e.g. Pulling public web services

HackJSONP!

Specification someday?XDR, Cross-Origin Resource Sharing

Tuesday, September 28, 2010

Page 25: Not your mother's JavaScript

Current state?

Tuesday, September 28, 2010

Page 26: Not your mother's JavaScript

Handling binary data

Tuesday, September 28, 2010

Page 27: Not your mother's JavaScript

Requirement?Dealing client-side with low level file formats and protocols

Tuesday, September 28, 2010

Page 28: Not your mother's JavaScript

Why?

Tuesday, September 28, 2010

Page 29: Not your mother's JavaScript

Low level file formatsParsing/Creating ZIP, PDF, SWF...

Tuesday, September 28, 2010

Page 30: Not your mother's JavaScript

Networking protocols

http://github.com/kanaka/noVNCTuesday, September 28, 2010

Page 31: Not your mother's JavaScript

Emulators

http://github.com/bfirsh/jsnes

http://www.kingsquare.nl/jsc64

Tuesday, September 28, 2010

Page 32: Not your mother's JavaScript

The hackvar xhr = new XMLHttpRequest();

xhr.open("GET", "test.png", false);xhr.overrideMimeType("text/plain; charset=x-user-defined");xhr.send();

if(200 != xhr.status){ var data = xhr.responseText;

for(var i = 0; undefined != data[i++];) var byteValue = data.charCodeAt(i) & 0xff; ... }}

Tuesday, September 28, 2010

Page 33: Not your mother's JavaScript

The hack?

Tuesday, September 28, 2010

Page 34: Not your mother's JavaScript

The hack?http://github.com/pkrumins/node-png

var sys = require("sys"), fs = require("fs");

var Png = require("png").Png, data = fs.readFileSync("data.bin"), png = new Png(data, Buffer.length / 4, 1, "RGBA");

png.encode(function(png_image){ sys.print(png_image);});

var img = Image;

img.onload = function(){ ctx.drawImage(img, 0, 0); var data = ctx.getImageData(0, 0, this.width, this.height); ...};

img.src = "data.png";

Tuesday, September 28, 2010

Page 35: Not your mother's JavaScript

Awesome, how to start hacking JavaScript?

Tuesday, September 28, 2010

Page 36: Not your mother's JavaScript

1. Know the limits!I mean, know the limits!!

You can't push the limits when the limits aren't there to begin with.

Tuesday, September 28, 2010

Page 37: Not your mother's JavaScript

2. Explore your browser’s microcosmos!

Missing API != Missing Feature

Tuesday, September 28, 2010

Page 38: Not your mother's JavaScript

Inflating Zlib datavar scanln = "\x00" + zlibData, adler = readInt() + 65536,

uri = "data:image/png;base64," + btoa("\x89PNG\r\n\x1A\n" + buildChunk("IHDR", toInt(zlibData.length / 4) +

toInt(1) + "\x08\x06\x00\x00\x00") + buildChunk("IDAT", "\x78\x9c\x00\x01\x00\xfe\xff" + scanln + toInt(adler)) + buildChunk("IEND", '')),

img = new Image; img.src = uri;

...

ctx.drawImage(img, 0, 0);

var inflatedData = ctx.getImageData(0, 0, img.width, img.height).data);

Tuesday, September 28, 2010

Page 39: Not your mother's JavaScript

Fake ctx.fillTextfunction fillText(ctx, font, textToDraw, x, y){ var img = new Image;

img.src = 'data:image/svg+xml,' + '<svg xmlns="http://www.w3.org/2000/svg">' + '<text x="' + x + '" y="' + y + '" ' + 'style="font:' + font + '">' + textToDraw + '</text>' + '</svg>';

ctx.drawImage(img, 0, 0);}

var ctx = document.body.appendChild( document.createElement("canvas")).getContext("2d");

fillText(ctx, "30px Arial", "Hello World!", 50, 50);

Tuesday, September 28, 2010

Page 40: Not your mother's JavaScript

3. Watch out for paperclips and gums

Use the wrong tools for the right job.

Tuesday, September 28, 2010

Page 41: Not your mother's JavaScript

Class autoloading["Person", "Ninja"].forEach(function(className){ window.__defineGetter__(className, function(){ return require(className + ".js"); });});

var person = new Person();

person.is_ninja = true;

if(person.is_ninja){ var ninji = new Ninja(person);}

Tuesday, September 28, 2010

Page 42: Not your mother's JavaScript

def.js

http://github.com/tobeytailor/def.js

def ("Person") ({ init: function(name){ this.name = name; }});

def ("Ninja") < Person ({ init: function(name){ this._super(); }});

var ninjy = new Ninja("JDD");

Tuesday, September 28, 2010

Page 43: Not your mother's JavaScript

Nonsense, yet

var1 += var2

Tuesday, September 28, 2010

Page 44: Not your mother's JavaScript

Nonsense, yet

window.__defineGetter__("var1", function(){ console.log("Function 1");});

Tuesday, September 28, 2010

Page 45: Not your mother's JavaScript

Nonsense, yet

window.__defineGetter__("var1", function(){ console.log("Function 1");

return { valueOf: function() { console.log("Function 3"); } }});

Tuesday, September 28, 2010

Page 46: Not your mother's JavaScript

Nonsense, yet

window.__defineGetter__("var2", function(){ console.log("Function 2");

return { valueOf: function() { console.log("Function 4"); } }});

Tuesday, September 28, 2010

Page 47: Not your mother's JavaScript

Nonsense, yet

window.__defineSetter__("var1", function(){ console.log("Function 5");});

Tuesday, September 28, 2010

Page 48: Not your mother's JavaScript

Thanks.@tobeytailor | github.com/tobeytailor | [email protected]

Tuesday, September 28, 2010