SlideShare a Scribd company logo
Beautiful JavaScript
      Ürgo Ringo
If Java was written as JavaScript
 public class MyApp {

     public   static   void main(String[] args) {...}
     public   static   void submit(HtmlForm nativeForm) {...}
     public   static   void registerNewProductEventHandler() {...}
     public   static   void newProduct(DomEvent event) {...}
     public   static   void keyUp(HtmlInput input) {...}
     public   static   void addInitialValueStorage(HtmlObject obj)
     public   static   void handleFormChanged(HtmlRow row, DomEvent e)
     public   static   void calculatePrices(DomEvent e) {...}
     public   static   void hide(HtmlRow row) {...}
     public   static   void select(HtmlRow row) {...}
     public   static   void selectRow(HtmlRow row) {...}
     public   static   void handleSelectViewEvent(DomEvent event) {...}
     public   static   void selectView(String id) {...}
     public   static   void showViewColumns(String viewId) {...}
     public   static   void initColumnWidths(String viewId) {...}
     public   static   void setViewLinkSelected(String viewId) {...}
     public   static   boolean isEmpty(String str) {...}
     public   static   String findCurrentView() {...}
     public   static   boolean newProduct(DomEvent event) {...}

 }
If Java was written as JavaScript (2)
public static void submit(HtmlForm nativeForm) {
  String queryString = jQueryUtils.wrap(nativeForm).serialize();
  JForm form = jQueryUtils.wrap(nativeForm);
  Url url = form.attr("action");
  String viewId = findCurrentView();
  String oldId = form.attr("id");

    jQueryUtils.post(url, queryString, (data) -> {
      String id = form.find("input[name='id']").attr("value");
      boolean isNew = isEmpty(id);
      String newId = jQueryUtils.wrap(data).attr("id");
      if (isNew) {
        jQueryUtils.wrap("#" + oldId).replace(data);
        registerNewProductEventHandler();
        showViewColumns(viewId);
        registerRowEventHandlers(newId);
      }else{
        String dataWithCorrectView = jQueryUtils.wrap(data).find("div").each({
          if (jQueryUtils.wrap(nativeForm).attr("id").indexOf(viewId) > -1) {
             jQueryUtils.wrap(nativeForm).removeClass("hidden");
          }
        });
        jQueryUtils.wrap("#"+oldId).html(dataWithCorrectView);
        registerRowEventHandlers(oldId);
      }
      jQueryUtils("#"+oldId).removeClass("div_table_row_selected");
    }).error((data) -> {
      if (oldId == "form-new"){
        data.setResponseText(data.responseText.replace("form-", oldId));
      }
      jQueryUtils.wrap("#"+oldId).replace(data.getResponseText());
      registerRowEventHandlers(oldId);
      showViewColumns(viewId);
      selectRow(jQueryUtils.wrap("#" + oldId));
    });
    return false;
}
module pattern
var myModule = (function () {

 var myPrivateVar;
 // A private counter variable
 myPrivateVar = 0;
 // A private function which logs any arguments
 function myPrivateMethod(foo) {
     console.log( foo );
 };
 return {
    // A public variable
    myPublicVar: "foo",
    // A public function utilizing privates
    myPublicFunction: function(bar) {
    // Increment our private counter
    myPrivateVar++;
    // Call our private method using bar
    myPrivateMethod(bar);
    }
 };
})();


   http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript
MVC frameworks
http://todomvc.com/

             What we compared
simple API
client side templating with binding
controller
ajax stubbing
see http://canjs.us/#why_canjs
food-app




https://github.com/ignite/food-app
sample Model
foodApp.Meal = can.Model({
     healthyLimit : {
         carbs : 15,
         fats : 20,
         proteins : 50
     }
}, {
     proteins : function() {
         var total = 0;
         this.products.each(function(el) {
             return total += el.proteins;
         });
         return total;
     },
     proteinsExceedHealthyLimit : function() {
         return this.proteins() > foodApp.Meal.healthyLimit.proteins;
     }
});
unit testing - jasmine
jasmine sample
describe("Meal", function() {

      it("calculates macronutrients using added products", function() {
          var meal = new foodApp.Meal();
          meal.products.push(new foodApp.Product({
               carbohydrates : 10,
               proteins : 25,
               fats : 30
          }));
          meal.products.push(new foodApp.Product({
               carbohydrates : 10,
               proteins : 25,
               fats : 30
          }));

            expect(meal.carbohydrates()).toEqual(20);
            expect(meal.proteins()).toEqual(50);
            expect(meal.fats()).toEqual(60);
      });

});
SVG vs Canvas for graphs
SVG
http://g.raphaeljs.com/
http://d3js.org/

Canvas
...
Other stuff
JSLint, JSHint

Underscore.js

CSS bootstraps
use Module pattern
use MVC framework
unit test JavaScript (e.g Jasmine)
use CSS bootstap
use JSHint, JSLint

More Related Content

ODP
Unit testing with Easymock
Ürgo Ringo
 
PPTX
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
solit
 
PDF
Stop Making Excuses and Start Testing Your JavaScript
Ryan Anklam
 
PDF
Redux Thunk - Fu - Fighting with Async
Artur Szott
 
PPTX
The secret unit testing tools no one ever told you about
Dror Helper
 
PDF
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
PDF
Mockito intro
Cristian R. Silva
 
PDF
Understanding JavaScript Testing
jeresig
 
Unit testing with Easymock
Ürgo Ringo
 
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
solit
 
Stop Making Excuses and Start Testing Your JavaScript
Ryan Anklam
 
Redux Thunk - Fu - Fighting with Async
Artur Szott
 
The secret unit testing tools no one ever told you about
Dror Helper
 
MeetJS Summit 2016: React.js enlightenment
Artur Szott
 
Mockito intro
Cristian R. Silva
 
Understanding JavaScript Testing
jeresig
 

What's hot (20)

PPTX
Unit testing patterns for concurrent code
Dror Helper
 
PPTX
Mockito intro
Jonathan Holloway
 
PPTX
JavaScript Proven Practises
Robert MacLean
 
KEY
Basic Unit Testing with Mockito
Alexander De Leon
 
PDF
Adventures In JavaScript Testing
Thomas Fuchs
 
PPT
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
PDF
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
PDF
Mocking in Java with Mockito
Richard Paul
 
PPTX
100% Code Coverage - TDD mit Java EE
Stefan Macke
 
PPTX
Mock your way with Mockito
Vitaly Polonetsky
 
PDF
iOS Talks 6: Unit Testing
Marin Benčević
 
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
PPTX
From clever code to better code
Dror Helper
 
PDF
Don't Make Android Bad... Again
Pedro Vicente
 
DOCX
Exercícios Netbeans - Vera Cymbron
cymbron
 
PDF
The Ring programming language version 1.10 book - Part 17 of 212
Mahmoud Samir Fayed
 
PDF
Magic methods
Matthew Barlocker
 
PDF
What the FUF?
An Doan
 
PPTX
PHP 5 Magic Methods
David Stockton
 
Unit testing patterns for concurrent code
Dror Helper
 
Mockito intro
Jonathan Holloway
 
JavaScript Proven Practises
Robert MacLean
 
Basic Unit Testing with Mockito
Alexander De Leon
 
Adventures In JavaScript Testing
Thomas Fuchs
 
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
Mocking in Java with Mockito
Richard Paul
 
100% Code Coverage - TDD mit Java EE
Stefan Macke
 
Mock your way with Mockito
Vitaly Polonetsky
 
iOS Talks 6: Unit Testing
Marin Benčević
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
From clever code to better code
Dror Helper
 
Don't Make Android Bad... Again
Pedro Vicente
 
Exercícios Netbeans - Vera Cymbron
cymbron
 
The Ring programming language version 1.10 book - Part 17 of 212
Mahmoud Samir Fayed
 
Magic methods
Matthew Barlocker
 
What the FUF?
An Doan
 
PHP 5 Magic Methods
David Stockton
 
Ad

Viewers also liked (16)

PPT
Žaizdų Kategorijos
urgo
 
ODP
RIA implementation patterns
Ürgo Ringo
 
PPT
Specificationby example
Ürgo Ringo
 
PDF
Small tools to improve your (agile) life
Ürgo Ringo
 
ODP
Domain Driven Design
Ürgo Ringo
 
ODP
Executable specifiaction
Ürgo Ringo
 
PDF
Introduction to TDD and BDD
Luis García Castro
 
PDF
Lunch and learn: Cucumber and Capybara
Marc Seeger
 
PPTX
Automated Acceptance Tests & Tool choice
toddbr
 
PPTX
BDD testing with cucumber
Daniel Kummer
 
PPTX
Test automation with Cucumber-JVM
Alan Parkinson
 
PDF
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
PDF
Behavior Driven Development and Automation Testing Using Cucumber
KMS Technology
 
PDF
Behavior Driven Development with Cucumber
Brandon Keepers
 
PDF
Writing Software not Code with Cucumber
Ben Mabey
 
PDF
8 Tips for an Awesome Powerpoint Presentation
Slides | Presentation Design Agency
 
Žaizdų Kategorijos
urgo
 
RIA implementation patterns
Ürgo Ringo
 
Specificationby example
Ürgo Ringo
 
Small tools to improve your (agile) life
Ürgo Ringo
 
Domain Driven Design
Ürgo Ringo
 
Executable specifiaction
Ürgo Ringo
 
Introduction to TDD and BDD
Luis García Castro
 
Lunch and learn: Cucumber and Capybara
Marc Seeger
 
Automated Acceptance Tests & Tool choice
toddbr
 
BDD testing with cucumber
Daniel Kummer
 
Test automation with Cucumber-JVM
Alan Parkinson
 
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Behavior Driven Development and Automation Testing Using Cucumber
KMS Technology
 
Behavior Driven Development with Cucumber
Brandon Keepers
 
Writing Software not Code with Cucumber
Ben Mabey
 
8 Tips for an Awesome Powerpoint Presentation
Slides | Presentation Design Agency
 
Ad

Similar to Beautiful java script (20)

PDF
Jason parsing
parallelminder
 
PDF
Swift Delhi: Practical POP
Natasha Murashev
 
PDF
Griffon @ Svwjug
Andres Almiray
 
DOCX
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 
PDF
Backbone Basics with Examples
Sergey Bolshchikov
 
PPTX
Taming that client side mess with Backbone.js
Jarod Ferguson
 
PDF
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
PDF
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
PROIDEA
 
PDF
Practical Protocol-Oriented-Programming
Natasha Murashev
 
PDF
Practialpop 160510130818
Shahzain Saeed
 
DOC
code for quiz in my sql
JOYITAKUNDU1
 
PDF
Clean Javascript
Ryunosuke SATO
 
PDF
Understanding backbonejs
Nick Lee
 
PDF
Speed up your GWT coding with gQuery
Manuel Carrasco Moñino
 
PDF
React 101
Casear Chu
 
PDF
Android Design Patterns
Godfrey Nolan
 
PDF
Vaadin7
Joonas Lehtinen
 
PPTX
Roman iovlev. Test UI with JDI - Selenium camp
Роман Иовлев
 
PDF
Crossing platforms with JavaScript & React
Robert DeLuca
 
PDF
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Jason parsing
parallelminder
 
Swift Delhi: Practical POP
Natasha Murashev
 
Griffon @ Svwjug
Andres Almiray
 
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 
Backbone Basics with Examples
Sergey Bolshchikov
 
Taming that client side mess with Backbone.js
Jarod Ferguson
 
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
PROIDEA
 
Practical Protocol-Oriented-Programming
Natasha Murashev
 
Practialpop 160510130818
Shahzain Saeed
 
code for quiz in my sql
JOYITAKUNDU1
 
Clean Javascript
Ryunosuke SATO
 
Understanding backbonejs
Nick Lee
 
Speed up your GWT coding with gQuery
Manuel Carrasco Moñino
 
React 101
Casear Chu
 
Android Design Patterns
Godfrey Nolan
 
Roman iovlev. Test UI with JDI - Selenium camp
Роман Иовлев
 
Crossing platforms with JavaScript & React
Robert DeLuca
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 

Recently uploaded (20)

PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
Software Development Company | KodekX
KodekX
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
Software Development Company | KodekX
KodekX
 

Beautiful java script

  • 1. Beautiful JavaScript Ürgo Ringo
  • 2. If Java was written as JavaScript public class MyApp { public static void main(String[] args) {...} public static void submit(HtmlForm nativeForm) {...} public static void registerNewProductEventHandler() {...} public static void newProduct(DomEvent event) {...} public static void keyUp(HtmlInput input) {...} public static void addInitialValueStorage(HtmlObject obj) public static void handleFormChanged(HtmlRow row, DomEvent e) public static void calculatePrices(DomEvent e) {...} public static void hide(HtmlRow row) {...} public static void select(HtmlRow row) {...} public static void selectRow(HtmlRow row) {...} public static void handleSelectViewEvent(DomEvent event) {...} public static void selectView(String id) {...} public static void showViewColumns(String viewId) {...} public static void initColumnWidths(String viewId) {...} public static void setViewLinkSelected(String viewId) {...} public static boolean isEmpty(String str) {...} public static String findCurrentView() {...} public static boolean newProduct(DomEvent event) {...} }
  • 3. If Java was written as JavaScript (2) public static void submit(HtmlForm nativeForm) { String queryString = jQueryUtils.wrap(nativeForm).serialize(); JForm form = jQueryUtils.wrap(nativeForm); Url url = form.attr("action"); String viewId = findCurrentView(); String oldId = form.attr("id"); jQueryUtils.post(url, queryString, (data) -> { String id = form.find("input[name='id']").attr("value"); boolean isNew = isEmpty(id); String newId = jQueryUtils.wrap(data).attr("id"); if (isNew) { jQueryUtils.wrap("#" + oldId).replace(data); registerNewProductEventHandler(); showViewColumns(viewId); registerRowEventHandlers(newId); }else{ String dataWithCorrectView = jQueryUtils.wrap(data).find("div").each({ if (jQueryUtils.wrap(nativeForm).attr("id").indexOf(viewId) > -1) { jQueryUtils.wrap(nativeForm).removeClass("hidden"); } }); jQueryUtils.wrap("#"+oldId).html(dataWithCorrectView); registerRowEventHandlers(oldId); } jQueryUtils("#"+oldId).removeClass("div_table_row_selected"); }).error((data) -> { if (oldId == "form-new"){ data.setResponseText(data.responseText.replace("form-", oldId)); } jQueryUtils.wrap("#"+oldId).replace(data.getResponseText()); registerRowEventHandlers(oldId); showViewColumns(viewId); selectRow(jQueryUtils.wrap("#" + oldId)); }); return false; }
  • 4. module pattern var myModule = (function () { var myPrivateVar; // A private counter variable myPrivateVar = 0; // A private function which logs any arguments function myPrivateMethod(foo) { console.log( foo ); }; return { // A public variable myPublicVar: "foo", // A public function utilizing privates myPublicFunction: function(bar) { // Increment our private counter myPrivateVar++; // Call our private method using bar myPrivateMethod(bar); } }; })(); http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript
  • 6. simple API client side templating with binding controller ajax stubbing see http://canjs.us/#why_canjs
  • 8. sample Model foodApp.Meal = can.Model({ healthyLimit : { carbs : 15, fats : 20, proteins : 50 } }, { proteins : function() { var total = 0; this.products.each(function(el) { return total += el.proteins; }); return total; }, proteinsExceedHealthyLimit : function() { return this.proteins() > foodApp.Meal.healthyLimit.proteins; } });
  • 9. unit testing - jasmine
  • 10. jasmine sample describe("Meal", function() { it("calculates macronutrients using added products", function() { var meal = new foodApp.Meal(); meal.products.push(new foodApp.Product({ carbohydrates : 10, proteins : 25, fats : 30 })); meal.products.push(new foodApp.Product({ carbohydrates : 10, proteins : 25, fats : 30 })); expect(meal.carbohydrates()).toEqual(20); expect(meal.proteins()).toEqual(50); expect(meal.fats()).toEqual(60); }); });
  • 11. SVG vs Canvas for graphs SVG http://g.raphaeljs.com/ http://d3js.org/ Canvas ...
  • 13. use Module pattern use MVC framework unit test JavaScript (e.g Jasmine) use CSS bootstap use JSHint, JSLint