SlideShare a Scribd company logo
1 of 30
{}
Javascript (ECMA)
Sandeepan
Level: Advanced – Part 1
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “Types” }
• Primitive
– undefined
– null
– Boolean
– Number
– String
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “Object” }
• Few important points:
– It is a collection of properties
– has single prototype object
– Prototype may be the null value
{}{ “topic” : “Object” }
• constructor:
– function object that creates and initializes objects
– The value of constructors “prototype” property is a prototype object that is used to
implement inheritance and shared properties
• prototype:
– object that provides shared properties for other objects
• native objects
– object whose scemantics are fully defined by specification rather than host environment.
– Eg: Object (constructor), Date, Math, parseInt, eval, string methods likeindexOf and replace,
array methods, ...
• built-in objects
– independent of host environment
• host objects
– object supplied by host environment
– Eg: (assuming browser environment): window, document, location, history,
XMLHttpRequest, setTimeout, getElementsByTagName, querySelectorAll
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “JSON” }
Source: http://www.json.org/
{}{ “topic” : “JSON” }
Source: http://www.json.org/
{}{ “topic” : “JSON” }
Source: http://www.json.org/
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “Defining Functions” }
• Using a function
• instantiate
Source: http://www.phpied.com/
{}{ “topic” : “Defining Functions” }
• Methods defined internally
• Methods added to the prototype
Source: http://www.phpied.com/
{}{ “topic” : “Defining Functions” }
• Using object literals
– For Object :
• var o = {};
• instead of the "normal" way var o = new Object();
– For arrays you can do:
• var a = [];
• instead of the "normal" way var o = new Array();
– Usage
Source: http://www.phpied.com/
{}{ “topic” : “Defining Functions” }
• Singleton using a function
• usage
Source: http://www.phpied.com/
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}{ “topic” : “inheritance” }
• Step 1: Create constructor function for Vehicle
• Step 2: Create constructor function Car
• Step 3: Set up dynamic inheritance
• Step 4: Extending Car using prototype
• Step 5: Creating a new Car
• Step 6: Extend Vehicle using prototype
Source: http://www.klauskomenda.com
{}Topics
• Types
• Object
• JSON
• Defining Functions
• Inheritance
• Guidelines
{}{ “topic” : “Guidelines” }
• Namespace pollution – CAREFULL
• Declaration with var – ALWAYS
• Context/ scope – BEWARE
• Separate JS file
• No embedded JS code in HTML file
– (unless specific to single session)
• Use the scripts tag as late as possible in html file.
• Coding
– Avoid mixins : as they always complicate the rendering engine and browser performance
– Function: declare before usage
– Indentation : 4 space
– Line length : avoid more than 80 chars
– Comments : preferable for each variables and be generous with comments
{}
Q & A
{}

Thank You

More Related Content

Similar to Javascript

Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
kevinvw
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
zand3rs
 

Similar to Javascript (20)

Python oop class 1
Python oop   class 1Python oop   class 1
Python oop class 1
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Introduction to OOP in Python
Introduction to OOP in PythonIntroduction to OOP in Python
Introduction to OOP in Python
 
Yeoman
YeomanYeoman
Yeoman
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online Training
 
React-Native Lecture 11: In App Storage
React-Native Lecture 11: In App StorageReact-Native Lecture 11: In App Storage
React-Native Lecture 11: In App Storage
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
 
Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 
Angular or React
Angular or ReactAngular or React
Angular or React
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Selenium bootcamp slides
Selenium bootcamp slides   Selenium bootcamp slides
Selenium bootcamp slides
 
Cypress.pptx
Cypress.pptxCypress.pptx
Cypress.pptx
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)
 
Mezzanine簡介 (at) Taichung.py
Mezzanine簡介 (at) Taichung.pyMezzanine簡介 (at) Taichung.py
Mezzanine簡介 (at) Taichung.py
 
State of search | drupal dinner
State of search | drupal dinnerState of search | drupal dinner
State of search | drupal dinner
 
Agile sites311training
Agile sites311trainingAgile sites311training
Agile sites311training
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 

Javascript

  • 2. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 3. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 4. {}{ “topic” : “Types” } • Primitive – undefined – null – Boolean – Number – String
  • 5. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 6. {}{ “topic” : “Object” } • Few important points: – It is a collection of properties – has single prototype object – Prototype may be the null value
  • 7. {}{ “topic” : “Object” } • constructor: – function object that creates and initializes objects – The value of constructors “prototype” property is a prototype object that is used to implement inheritance and shared properties • prototype: – object that provides shared properties for other objects • native objects – object whose scemantics are fully defined by specification rather than host environment. – Eg: Object (constructor), Date, Math, parseInt, eval, string methods likeindexOf and replace, array methods, ... • built-in objects – independent of host environment • host objects – object supplied by host environment – Eg: (assuming browser environment): window, document, location, history, XMLHttpRequest, setTimeout, getElementsByTagName, querySelectorAll
  • 8. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 9. {}{ “topic” : “JSON” } Source: http://www.json.org/
  • 10. {}{ “topic” : “JSON” } Source: http://www.json.org/
  • 11. {}{ “topic” : “JSON” } Source: http://www.json.org/
  • 12. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 13. {}{ “topic” : “Defining Functions” } • Using a function • instantiate Source: http://www.phpied.com/
  • 14. {}{ “topic” : “Defining Functions” } • Methods defined internally • Methods added to the prototype Source: http://www.phpied.com/
  • 15. {}{ “topic” : “Defining Functions” } • Using object literals – For Object : • var o = {}; • instead of the "normal" way var o = new Object(); – For arrays you can do: • var a = []; • instead of the "normal" way var o = new Array(); – Usage Source: http://www.phpied.com/
  • 16. {}{ “topic” : “Defining Functions” } • Singleton using a function • usage Source: http://www.phpied.com/
  • 17. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 18. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 19. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 20. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 21. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 22. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 23. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 24. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 25. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 26. {}{ “topic” : “inheritance” } • Step 1: Create constructor function for Vehicle • Step 2: Create constructor function Car • Step 3: Set up dynamic inheritance • Step 4: Extending Car using prototype • Step 5: Creating a new Car • Step 6: Extend Vehicle using prototype Source: http://www.klauskomenda.com
  • 27. {}Topics • Types • Object • JSON • Defining Functions • Inheritance • Guidelines
  • 28. {}{ “topic” : “Guidelines” } • Namespace pollution – CAREFULL • Declaration with var – ALWAYS • Context/ scope – BEWARE • Separate JS file • No embedded JS code in HTML file – (unless specific to single session) • Use the scripts tag as late as possible in html file. • Coding – Avoid mixins : as they always complicate the rendering engine and browser performance – Function: declare before usage – Indentation : 4 space – Line length : avoid more than 80 chars – Comments : preferable for each variables and be generous with comments

Editor's Notes

  1. Same function using object literalIn this case you don't need to (and cannot) create an instance of the class, it already exists. So you simply start using this instance.
  2. * Function to define singleton object
  3. What JavaScript does when it reaches that statement is the following:-The new operator creates a generic object and assigns its __proto__ property to Vehicle.prototype-The new operator passes the object to the Vehicle constructor function as the this keyword.-The object gets the properties hasEngine and hasWheels assigned-Upon return from the constructor, the object gets assigned to Car.prototype