SlideShare a Scribd company logo
1 of 14
[object Object],[object Object],Sergey Ilinsky ( @ilinsky )
1. What is wrong with my code? (bad library story) jQuery: >  $(document).each() TypeError: b is undefined >  $(document).click("alert(1)") TypeError: d is undefined >  $(document).map(null) TypeError: a is null Dojo: >  dojo.stopEvent() TypeError: evt is undefined >  dojo.ready([new Function])  TypeError: mll[x] is not a function >  dojo.map(null) TypeError: arr is null
1. What is wrong with my code? (good library story) An other library (Ample SDK): >  ample.documentElement.removeChild() Missing required 1st argument "node"  in "removeChild" function call >  ample.querySelector("xul|textbox[type=number]", 11); Incompatible type of 2nd argument "NSResolver"  in "querySelector" function call. Expecting "Function" >  ample.importNode(null) null is not allowed value of 1st argument "node"  in "importNode" function call
2. Why is it important to validate library API call?
2. Why is it important to validate library API call? 1) Helps library user (end developer) to find problems more efficiently
2. Why is it important to validate library API call? 1) Helps library user (end developer) to find problems more efficiently 2) Prevents library from internal failure caused by improper call
3. Three aspects of API call validation 1) Arguments requiredness ,[object Object]
3) null values
4. Guard.js — API validation library Guard.js  is a “broker library” that helps you  validating API calls to your “public library».  4.1) Using Guard.js 4.2) Guard exceptions in try/catch statements 4.3) Data types support 4.4) Validation execution overhead
4.1 Using Guard.js // Your «public library» code myObject.myFunction = function(sName, fHandler, bDirection, oArguments) { // Validate API function call Guard(arguments, [ // 'name' is required, must be string ["name",  String], // 'handler' is required, must be function ["handler",  Function], // 'direction' is optional, if passed must be boolean or null ["direction", Boolean, true, true], // 'arguments' is optional, if passed must be JS arguments object ["arguments", Guard.Arguments, true] ]); // Execute your library function here return "the output of myLibraryFunction"; };
4.2 Guard exceptions in try/catch statements function testMyObjectFunction() { try { myObjectFunction(3); } catch (e) { alert(e.caller) // ->  testMyObjectFunction } } testMyObjectFunction();
4.3 Data types support - Primitive Types - String - Number - Boolean - Object - «Object» Types - Array - Function - Date - RegExp - Special Types - Guard.Arguments - Custom Types - Any constructor function reference
10% 4.4 Validation execution overhead
[object Object],if (!window.XMLHttpRequest) { window.XMLHttpRequest = function() { return new ActiveXObject(“Microsoft.XMLHTTP”); } } 1) Signing Object window.XMLHttpRequest.prototype.toString = function() { return “[object XMLHttpRequest]”; } alert(new XMLHttpRequest) // [object XMLHttpRequest] 2) Signing Function window.XMLHttpRequest.toString = function() { return “function XMLHttpRequest() {[my library code]}”; } alert(XMLHttpRequest) // function XMLHttpRequest() { [my library code] }

More Related Content

What's hot

Ant - Another Neat Tool
Ant - Another Neat ToolAnt - Another Neat Tool
Ant - Another Neat Tool
Kanika2885
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
inovex GmbH
 

What's hot (20)

Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Ant - Another Neat Tool
Ant - Another Neat ToolAnt - Another Neat Tool
Ant - Another Neat Tool
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Types End-to-End @ samsara
Types End-to-End @ samsaraTypes End-to-End @ samsara
Types End-to-End @ samsara
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]Fundamental JavaScript [In Control 2009]
Fundamental JavaScript [In Control 2009]
 
Jsp And Jdbc
Jsp And JdbcJsp And Jdbc
Jsp And Jdbc
 
SharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuerySharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuery
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 min
 
Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!Ruby & Python with Silverlight O RLY? YA RLY!
Ruby & Python with Silverlight O RLY? YA RLY!
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
 
Design attern in php
Design attern in phpDesign attern in php
Design attern in php
 

Similar to JavaScript APIs In Focus

Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
Javascript Ks
Javascript KsJavascript Ks
Javascript Ks
ssetem
 

Similar to JavaScript APIs In Focus (20)

Java Intro
Java IntroJava Intro
Java Intro
 
JavaScript: The Language
JavaScript: The LanguageJavaScript: The Language
JavaScript: The Language
 
jQuery Presentation - Refresh Events
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh Events
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
Javascript Ks
Javascript KsJavascript Ks
Javascript Ks
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
jQuery
jQueryjQuery
jQuery
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancement
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

JavaScript APIs In Focus

  • 1.
  • 2. 1. What is wrong with my code? (bad library story) jQuery: > $(document).each() TypeError: b is undefined > $(document).click("alert(1)") TypeError: d is undefined > $(document).map(null) TypeError: a is null Dojo: > dojo.stopEvent() TypeError: evt is undefined > dojo.ready([new Function]) TypeError: mll[x] is not a function > dojo.map(null) TypeError: arr is null
  • 3. 1. What is wrong with my code? (good library story) An other library (Ample SDK): > ample.documentElement.removeChild() Missing required 1st argument "node" in "removeChild" function call > ample.querySelector("xul|textbox[type=number]", 11); Incompatible type of 2nd argument "NSResolver" in "querySelector" function call. Expecting "Function" > ample.importNode(null) null is not allowed value of 1st argument "node" in "importNode" function call
  • 4. 2. Why is it important to validate library API call?
  • 5. 2. Why is it important to validate library API call? 1) Helps library user (end developer) to find problems more efficiently
  • 6. 2. Why is it important to validate library API call? 1) Helps library user (end developer) to find problems more efficiently 2) Prevents library from internal failure caused by improper call
  • 7.
  • 9. 4. Guard.js — API validation library Guard.js is a “broker library” that helps you validating API calls to your “public library». 4.1) Using Guard.js 4.2) Guard exceptions in try/catch statements 4.3) Data types support 4.4) Validation execution overhead
  • 10. 4.1 Using Guard.js // Your «public library» code myObject.myFunction = function(sName, fHandler, bDirection, oArguments) { // Validate API function call Guard(arguments, [ // 'name' is required, must be string ["name", String], // 'handler' is required, must be function ["handler", Function], // 'direction' is optional, if passed must be boolean or null ["direction", Boolean, true, true], // 'arguments' is optional, if passed must be JS arguments object ["arguments", Guard.Arguments, true] ]); // Execute your library function here return "the output of myLibraryFunction"; };
  • 11. 4.2 Guard exceptions in try/catch statements function testMyObjectFunction() { try { myObjectFunction(3); } catch (e) { alert(e.caller) // -> testMyObjectFunction } } testMyObjectFunction();
  • 12. 4.3 Data types support - Primitive Types - String - Number - Boolean - Object - «Object» Types - Array - Function - Date - RegExp - Special Types - Guard.Arguments - Custom Types - Any constructor function reference
  • 13. 10% 4.4 Validation execution overhead
  • 14.
  • 15.
  • 18.