SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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

Hinweis der Redaktion

  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