SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à Javascript

Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
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 EngineGary Yeh
 
Selenium Online Training
Selenium  Online TrainingSelenium  Online Training
Selenium Online TrainingLearntek1
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGentkevinvw
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
Cypress.pptx
Cypress.pptxCypress.pptx
Cypress.pptxArshad QA
 
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 javaagorolabs
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN StackTroy Miles
 
Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)Webium: Page Objects In Python (Eng)
Webium: Page Objects In Python (Eng)Uladzimir Franskevich
 
Mezzanine簡介 (at) Taichung.py
Mezzanine簡介 (at) Taichung.pyMezzanine簡介 (at) Taichung.py
Mezzanine簡介 (at) Taichung.pyMax Lai
 
State of search | drupal dinner
State of search | drupal dinnerState of search | drupal dinner
State of search | drupal dinnerJoris Vercammen
 

Similaire à 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
 

Dernier

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...Jeffrey Haguewood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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 FMESafe Software
 
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 SavingEdi Saputra
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
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.pptxRemote DBA Services
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 AmsterdamUiPathCommunity
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Dernier (20)

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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

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

Notes de l'éditeur

  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