SlideShare a Scribd company logo
1 of 48
Download to read offline
Tuesday, September 28, 2010
Not your mother’s
                                 JavaScript
                              Tobias Schneider, @tobeytailor - uxebu
                                      Sep 26 2010, jsconf.eu




Tuesday, September 28, 2010
@tobeytailor
                                  Munich based web worker
                          Born as a natural coder in the Black Forrest
                              JavaScript hacker for ~8 years now
                          Pushing limits for uxebu since August 2010

                    5 GitHub projects, 1626 watchers, 1143 followers
                                       3 bad jokes
Tuesday, September 28, 2010
So you’re a hacker,
                        but why JavaScript?
                              Small, fast and widely misunderstood
                               Most flexible language of the world
                                It’s open & almost everywhere
                                      Hack driven enhanced
                                        You can haz jsconf

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


Tuesday, September 28, 2010
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
Hack driven enhancement
                  The evolution of JavaScript is a history full of workarounds.




Tuesday, September 28, 2010
First, there’s a limitation



Tuesday, September 28, 2010
Then there’s a hack



Tuesday, September 28, 2010
The interwebs likes it?



Tuesday, September 28, 2010
Then it gets a buzzy
                  name and becomes a
                        standard


Tuesday, September 28, 2010
Do you remember...
                                   AJAX in 2001?
                                Canvas before 2004?
                              Cross Domain Ajax 2010?




Tuesday, September 28, 2010
AJAX 2001
                                  Requirement:
                 Requesting the server without reloading the whole
                          page again & again & again...




Tuesday, September 28, 2010
AJAX 2001
                                  Requirement:
                 Requesting the server without reloading the whole
                          page again & again & again...
                                     Why?
                               Loading data async




Tuesday, September 28, 2010
AJAX 2001
                                  Requirement:
                 Requesting the server without reloading the whole
                          page again & again & again...
                                     Why?
                               Loading data async

                                      Hack
                                   iFrame fun




Tuesday, September 28, 2010
AJAX 2001
                                  Requirement:
                 Requesting the server without reloading the whole
                          page again & again & again...
                                     Why?
                               Loading data async

                                      Hack
                                   iFrame fun

                               Specification today
                                       XHR


Tuesday, September 28, 2010
Canvas 2003
                                      Requirement:
                              Drawing pictures in the browser




Tuesday, September 28, 2010
Canvas 2003
                                      Requirement:
                              Drawing pictures in the browser

                                          Why?
                                        LASERS!!!




Tuesday, September 28, 2010
Canvas 2003
                                           Requirement:
                                   Drawing pictures in the browser

                                                Why?
                                              LASERS!!!

                                                  Hack
                              Tons of IMG’s in your DOM rendered with IM




Tuesday, September 28, 2010
Canvas 2003
                                           Requirement:
                                   Drawing pictures in the browser

                                                Why?
                                              LASERS!!!

                                                  Hack
                              Tons of IMG’s in your DOM rendered with IM

                                         Specification today
                                       Canvas API (ExCanvas!)

Tuesday, September 28, 2010
Cross Domain Ajax
                                      Requirement:
                    Having a script from domain X loading data from Y




Tuesday, September 28, 2010
Cross Domain Ajax
                                      Requirement:
                    Having a script from domain X loading data from Y

                                              Why?
                                e.g. Pulling public web services




Tuesday, September 28, 2010
Cross Domain Ajax
                                      Requirement:
                    Having a script from domain X loading data from Y

                                              Why?
                                e.g. Pulling public web services

                                             Hack
                                            JSONP




Tuesday, September 28, 2010
Cross Domain Ajax
                                      Requirement:
                    Having a script from domain X loading data from Y

                                              Why?
                                e.g. Pulling public web services

                                             Hack
                                            JSONP!




Tuesday, September 28, 2010
Cross Domain Ajax
                                      Requirement:
                    Having a script from domain X loading data from Y

                                               Why?
                                 e.g. Pulling public web services

                                              Hack
                                             JSONP!

                                     Specification someday?
                               XDR, Cross-Origin Resource Sharing

Tuesday, September 28, 2010
Current state?



Tuesday, September 28, 2010
Handling binary data



Tuesday, September 28, 2010
Requirement?
     Dealing client-side with low level file formats and protocols




Tuesday, September 28, 2010
Why?



Tuesday, September 28, 2010
Low level file formats
                              Parsing/Creating ZIP, PDF, SWF...




Tuesday, September 28, 2010
Networking protocols




                              http://github.com/kanaka/noVNC
Tuesday, September 28, 2010
Emulators




   http://github.com/bfirsh/jsnes
                                 http://www.kingsquare.nl/jsc64

Tuesday, September 28, 2010
The hack
            var 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
The hack?




Tuesday, September 28, 2010
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
Awesome, how to
                               start hacking
                                JavaScript?


Tuesday, September 28, 2010
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
2. Explore your browser’s
           microcosmos!
                              Missing API != Missing Feature




Tuesday, September 28, 2010
Inflating Zlib data
         var scanln = "x00" + zlibData,
             adler = readInt() + 65536,

                uri = "data:image/png;base64," + btoa("x89PNGrnx1An" +
                  buildChunk("IHDR", toInt(zlibData.length / 4) +
                    toInt(1) + "x08x06x00x00x00") +
                  buildChunk("IDAT", "x78x9cx00x01x00xfexff" + 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
Fake ctx.fillText
                     function 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
3. Watch out for
                     paperclips and gums
                              Use the wrong tools for the right job.




Tuesday, September 28, 2010
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
def.js
                                   def ("Person") ({
                                       init: function(name){
                                           this.name = name;
                                       }
                                   });

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

                                   var ninjy = new Ninja("JDD");



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

Tuesday, September 28, 2010
Nonsense, yet


                                  var1 += var2




Tuesday, September 28, 2010
Nonsense, yet


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




Tuesday, September 28, 2010
Nonsense, yet

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

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




Tuesday, September 28, 2010
Nonsense, yet

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

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




Tuesday, September 28, 2010
Nonsense, yet


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




Tuesday, September 28, 2010
Thanks.
                @tobeytailor | github.com/tobeytailor | schneider@uxebu.com




Tuesday, September 28, 2010

More Related Content

Similar to Not your mother's JavaScript

Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets introkompozer
 
Whats Ajax Cheatsheet
Whats Ajax CheatsheetWhats Ajax Cheatsheet
Whats Ajax Cheatsheet51 lecture
 
Whats Ajax Cheatsheet
Whats Ajax CheatsheetWhats Ajax Cheatsheet
Whats Ajax Cheatsheet51 lecture
 
SenchaLabs Connect & Express
SenchaLabs Connect & ExpressSenchaLabs Connect & Express
SenchaLabs Connect & ExpressTim Caswell
 
Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Corpeño
 
Google - Charla para CTOs
Google - Charla para CTOsGoogle - Charla para CTOs
Google - Charla para CTOsPalermo Valley
 

Similar to Not your mother's JavaScript (7)

Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets intro
 
Whats Ajax Cheatsheet
Whats Ajax CheatsheetWhats Ajax Cheatsheet
Whats Ajax Cheatsheet
 
Slide Test
Slide TestSlide Test
Slide Test
 
Whats Ajax Cheatsheet
Whats Ajax CheatsheetWhats Ajax Cheatsheet
Whats Ajax Cheatsheet
 
SenchaLabs Connect & Express
SenchaLabs Connect & ExpressSenchaLabs Connect & Express
SenchaLabs Connect & Express
 
Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.Alejandro Villanueva - Google Inc.
Alejandro Villanueva - Google Inc.
 
Google - Charla para CTOs
Google - Charla para CTOsGoogle - Charla para CTOs
Google - Charla para CTOs
 

Recently uploaded

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 

Recently uploaded (20)

Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 

Not your mother's JavaScript

  • 2. Not your mother’s JavaScript Tobias Schneider, @tobeytailor - uxebu Sep 26 2010, jsconf.eu Tuesday, September 28, 2010
  • 3. @tobeytailor Munich based web worker Born as a natural coder in the Black Forrest JavaScript hacker for ~8 years now Pushing limits for uxebu since August 2010 5 GitHub projects, 1626 watchers, 1143 followers 3 bad jokes Tuesday, September 28, 2010
  • 4. So you’re a hacker, but why JavaScript? Small, fast and widely misunderstood Most flexible language of the world It’s open & almost everywhere Hack driven enhanced You can haz jsconf It isn’t perfect, still has lots of limits and constrains... Tuesday, September 28, 2010
  • 5. 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
  • 6. Hack driven enhancement The evolution of JavaScript is a history full of workarounds. Tuesday, September 28, 2010
  • 7. First, there’s a limitation Tuesday, September 28, 2010
  • 8. Then there’s a hack Tuesday, September 28, 2010
  • 9. The interwebs likes it? Tuesday, September 28, 2010
  • 10. Then it gets a buzzy name and becomes a standard Tuesday, September 28, 2010
  • 11. Do you remember... AJAX in 2001? Canvas before 2004? Cross Domain Ajax 2010? Tuesday, September 28, 2010
  • 12. AJAX 2001 Requirement: Requesting the server without reloading the whole page again & again & again... Tuesday, September 28, 2010
  • 13. AJAX 2001 Requirement: Requesting the server without reloading the whole page again & again & again... Why? Loading data async Tuesday, September 28, 2010
  • 14. AJAX 2001 Requirement: Requesting the server without reloading the whole page again & again & again... Why? Loading data async Hack iFrame fun Tuesday, September 28, 2010
  • 15. AJAX 2001 Requirement: Requesting the server without reloading the whole page again & again & again... Why? Loading data async Hack iFrame fun Specification today XHR Tuesday, September 28, 2010
  • 16. Canvas 2003 Requirement: Drawing pictures in the browser Tuesday, September 28, 2010
  • 17. Canvas 2003 Requirement: Drawing pictures in the browser Why? LASERS!!! Tuesday, September 28, 2010
  • 18. Canvas 2003 Requirement: Drawing pictures in the browser Why? LASERS!!! Hack Tons of IMG’s in your DOM rendered with IM Tuesday, September 28, 2010
  • 19. Canvas 2003 Requirement: Drawing pictures in the browser Why? LASERS!!! Hack Tons of IMG’s in your DOM rendered with IM Specification today Canvas API (ExCanvas!) Tuesday, September 28, 2010
  • 20. Cross Domain Ajax Requirement: Having a script from domain X loading data from Y Tuesday, September 28, 2010
  • 21. Cross Domain Ajax Requirement: Having a script from domain X loading data from Y Why? e.g. Pulling public web services Tuesday, September 28, 2010
  • 22. Cross Domain Ajax Requirement: Having a script from domain X loading data from Y Why? e.g. Pulling public web services Hack JSONP Tuesday, September 28, 2010
  • 23. Cross Domain Ajax Requirement: Having a script from domain X loading data from Y Why? e.g. Pulling public web services Hack JSONP! Tuesday, September 28, 2010
  • 24. Cross Domain Ajax Requirement: Having a script from domain X loading data from Y Why? e.g. Pulling public web services Hack JSONP! Specification someday? XDR, Cross-Origin Resource Sharing Tuesday, September 28, 2010
  • 26. Handling binary data Tuesday, September 28, 2010
  • 27. Requirement? Dealing client-side with low level file formats and protocols Tuesday, September 28, 2010
  • 29. Low level file formats Parsing/Creating ZIP, PDF, SWF... Tuesday, September 28, 2010
  • 30. Networking protocols http://github.com/kanaka/noVNC Tuesday, September 28, 2010
  • 31. Emulators http://github.com/bfirsh/jsnes http://www.kingsquare.nl/jsc64 Tuesday, September 28, 2010
  • 32. The hack var 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
  • 34. 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
  • 35. Awesome, how to start hacking JavaScript? Tuesday, September 28, 2010
  • 36. 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
  • 37. 2. Explore your browser’s microcosmos! Missing API != Missing Feature Tuesday, September 28, 2010
  • 38. Inflating Zlib data var scanln = "x00" + zlibData, adler = readInt() + 65536, uri = "data:image/png;base64," + btoa("x89PNGrnx1An" + buildChunk("IHDR", toInt(zlibData.length / 4) + toInt(1) + "x08x06x00x00x00") + buildChunk("IDAT", "x78x9cx00x01x00xfexff" + 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
  • 39. Fake ctx.fillText function 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
  • 40. 3. Watch out for paperclips and gums Use the wrong tools for the right job. Tuesday, September 28, 2010
  • 41. 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
  • 42. def.js def ("Person") ({ init: function(name){ this.name = name; } }); def ("Ninja") < Person ({ init: function(name){ this._super(); } }); var ninjy = new Ninja("JDD"); http://github.com/tobeytailor/def.js Tuesday, September 28, 2010
  • 43. Nonsense, yet var1 += var2 Tuesday, September 28, 2010
  • 44. Nonsense, yet window.__defineGetter__("var1", function(){ console.log("Function 1"); }); Tuesday, September 28, 2010
  • 45. Nonsense, yet window.__defineGetter__("var1", function(){ console.log("Function 1"); return { valueOf: function() { console.log("Function 3"); } } }); Tuesday, September 28, 2010
  • 46. Nonsense, yet window.__defineGetter__("var2", function(){ console.log("Function 2"); return { valueOf: function() { console.log("Function 4"); } } }); Tuesday, September 28, 2010
  • 47. Nonsense, yet window.__defineSetter__("var1", function(){ console.log("Function 5"); }); Tuesday, September 28, 2010
  • 48. Thanks. @tobeytailor | github.com/tobeytailor | schneider@uxebu.com Tuesday, September 28, 2010