SlideShare a Scribd company logo
Java Script
Tips & Tricks
They help us write better code using proven practices and not reinvent the wheel.They help us write better code using proven practices and not reinvent the wheel.
They help us write better code using proven practices and not reinvent the wheel.They provide a level of abstraction
They help us write better code using proven practices and not reinvent the wheel.They improve communication between developers and teams.
Design patternsDesign patterns Design patternsCoding patterns
singleton
factory
decorator
observer
...
JavaScript
specific
patterns
Design patternsObject-Oriented
Design patternsNo Classes
Design patternsPrototypes
Design patternsEnvironment
Objects
Native Host
Minimizing Globals
var a = (b = 0);
Single var Pattern Benefits
• Provides a single place to look for all the local variables
needed by the function
• Prevents logical errors when a variable is used before
it’s defined
• Helps you remember to declare variables and therefore
minimize globals
• Is less code
Hoisting
Access to the Global Object
For Loops HTMLCollections
• document.getElementsByName()
• document.getElementsByClassName()
• document.getElementsByTagName()
...
First-class objects Provide scope
Functions are objects that:
• Can be created dynamically at runtime, during the execution of the program
• Can be assigned to variables, can have their references copied to other variables,
can be augmented, and, except for a few special cases, can be deleted
• Can be passed as arguments to other functions and can also be returned by other
functions
• Can have their own properties and methods
Any variable defined with var inside of a
function is a local variable, invisible
outside the function.
Defining a function
Function expression Function declarations
Function expression VS Function declarations
Read-only name property
Function Hoisting
Callbacks are in
- Asynchronous Event Listeners
- Timeouts
- Libraries
- ...
- It provides a scope sandbox for your initialization
code
- Executes a function as soon as it is defined
Parameters of an Immediate Function Returned Values from Immediate Functions
Classical Pattern #1—The Default Pattern
Classical Pattern #1—The Default Pattern
Drawbacks
- Inherit both own properties added to
this and prototype properties
- It doesn’t enable you to pass
parameters to the child constructor
Classical Pattern #2—Rent-a-Constructor
Classical Pattern #2—Rent-a-Constructor
The drawback is that nothing from the
prototype gets inherited
A benefit is that you get true copies of the
parent’s own members, and there’s no risk
that a child can accidentally overwrite a
parent’s property.
Classical Pattern #3—Rent and Set Prototype
+ The result objects get copies of the parent’s own members and
references to the parent’s reusable functionality (implemented as
members of the prototype)
+ The child can also pass any arguments to the parent constructor
- The parent constructor is called twice
Classical Pattern #4—Share the Prototype
Classical Pattern #1 inherit Changed inherit
- If one child or grandchild somewhere down the inheritance chain modifies the
prototype, it affects all parents and grandparents.
Classical Pattern #5—A Temporary Constructor
+ The child only inherits properties of
the prototype
- We don’t have a reference to the
original parent
Another methods
With the class keyword
ECMAScript 6 introduced a new set
of keywords implementing classes.
Although these constructs look like
those familiar to developers of class-
based languages, they are not.
JavaScript remains prototype-based.
The new keywords include class,
constructor, static, extends, and
super.
With Object.create
ECMAScript 5 introduced a new
method: Object.create(). Calling
this method creates a new object.
The prototype of this object is the
first argument of the function:
Js tips & tricks

More Related Content

What's hot

Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
David Keener
 
From Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextFrom Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with Xtext
Karsten Thoms
 
Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013
Hung Lin
 
Rails best practices
Rails best practicesRails best practices
Rails best practices
Achintya Kumar
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
Ryan Riley
 
A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
Mykhailo Kotsur
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
Emre Akış
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
mperham
 
Akka framework
Akka frameworkAkka framework
Akka framework
mitesh_sharma
 
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
Endava
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with Xtext
GlobalLogic Ukraine
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
Decorator pattern
Decorator patternDecorator pattern
Decorator pattern
Mohammad Reda Katby
 
Why the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID ArchitectureWhy the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID Architecture
Jorge Ortiz
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
Milan Vukoje
 
Dive into Akka Actors
Dive into Akka ActorsDive into Akka Actors
Dive into Akka Actors
Knoldus Inc.
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
Daniel Fagnan
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
Brian Zitzow
 
Akka Fundamentals
Akka FundamentalsAkka Fundamentals
Akka Fundamentals
Michael Kendra
 
Javascript interview questions and answers
Javascript interview questions and answersJavascript interview questions and answers
Javascript interview questions and answers
FeedGoCode
 

What's hot (20)

Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 
From Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with XtextFrom Stairway to Heaven onto the Highway to Hell with Xtext
From Stairway to Heaven onto the Highway to Hell with Xtext
 
Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013
 
Rails best practices
Rails best practicesRails best practices
Rails best practices
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
A gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor modelA gentle introduction into AKKA and the actor model
A gentle introduction into AKKA and the actor model
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Akka framework
Akka frameworkAkka framework
Akka framework
 
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with Xtext
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Decorator pattern
Decorator patternDecorator pattern
Decorator pattern
 
Why the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID ArchitectureWhy the Dark Side should use Swift and a SOLID Architecture
Why the Dark Side should use Swift and a SOLID Architecture
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
Dive into Akka Actors
Dive into Akka ActorsDive into Akka Actors
Dive into Akka Actors
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
Java design patterns
Java design patternsJava design patterns
Java design patterns
 
Akka Fundamentals
Akka FundamentalsAkka Fundamentals
Akka Fundamentals
 
Javascript interview questions and answers
Javascript interview questions and answersJavascript interview questions and answers
Javascript interview questions and answers
 

Similar to Js tips & tricks

Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever Code
Gabor Varadi
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
Iulian Ilie-Némedi
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
Ayush Sharma
 
Software Design
Software DesignSoftware Design
Software Design
Ahmed Misbah
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
ConSanFrancisco123
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
eddiehaber
 
Python mocking intro
Python mocking introPython mocking intro
Python mocking intro
Hans Jones
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
Salvatore Fazio
 
walkmod - JUG talk
walkmod - JUG talkwalkmod - JUG talk
walkmod - JUG talk
walkmod
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
Dmitry Vinnik
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
Julie Iskander
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
walkmod
 
Ruby codebases in an entropic universe
Ruby codebases in an entropic universeRuby codebases in an entropic universe
Ruby codebases in an entropic universe
Niranjan Paranjape
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
Axway Appcelerator
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
Erick M'bwana
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
Yuri Visser
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
John Mulhall
 

Similar to Js tips & tricks (20)

Guide to Destroying Codebases The Demise of Clever Code
Guide to Destroying Codebases   The Demise of Clever CodeGuide to Destroying Codebases   The Demise of Clever Code
Guide to Destroying Codebases The Demise of Clever Code
 
Automate Design Patterns
Automate Design PatternsAutomate Design Patterns
Automate Design Patterns
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
Software Design
Software DesignSoftware Design
Software Design
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
Python mocking intro
Python mocking introPython mocking intro
Python mocking intro
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
walkmod - JUG talk
walkmod - JUG talkwalkmod - JUG talk
walkmod - JUG talk
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod33rd degree talk: open and automatic coding conventions with walkmod
33rd degree talk: open and automatic coding conventions with walkmod
 
Ruby codebases in an entropic universe
Ruby codebases in an entropic universeRuby codebases in an entropic universe
Ruby codebases in an entropic universe
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 

Recently uploaded

GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

Js tips & tricks

  • 2. They help us write better code using proven practices and not reinvent the wheel.They help us write better code using proven practices and not reinvent the wheel. They help us write better code using proven practices and not reinvent the wheel.They provide a level of abstraction They help us write better code using proven practices and not reinvent the wheel.They improve communication between developers and teams.
  • 3. Design patternsDesign patterns Design patternsCoding patterns singleton factory decorator observer ... JavaScript specific patterns
  • 4. Design patternsObject-Oriented Design patternsNo Classes Design patternsPrototypes Design patternsEnvironment Objects Native Host
  • 6. var a = (b = 0);
  • 7. Single var Pattern Benefits • Provides a single place to look for all the local variables needed by the function • Prevents logical errors when a variable is used before it’s defined • Helps you remember to declare variables and therefore minimize globals • Is less code
  • 9. Access to the Global Object
  • 10. For Loops HTMLCollections • document.getElementsByName() • document.getElementsByClassName() • document.getElementsByTagName() ...
  • 11. First-class objects Provide scope Functions are objects that: • Can be created dynamically at runtime, during the execution of the program • Can be assigned to variables, can have their references copied to other variables, can be augmented, and, except for a few special cases, can be deleted • Can be passed as arguments to other functions and can also be returned by other functions • Can have their own properties and methods Any variable defined with var inside of a function is a local variable, invisible outside the function.
  • 12. Defining a function Function expression Function declarations
  • 13. Function expression VS Function declarations Read-only name property Function Hoisting
  • 14. Callbacks are in - Asynchronous Event Listeners - Timeouts - Libraries - ...
  • 15.
  • 16.
  • 17. - It provides a scope sandbox for your initialization code - Executes a function as soon as it is defined Parameters of an Immediate Function Returned Values from Immediate Functions
  • 18.
  • 19.
  • 20.
  • 21. Classical Pattern #1—The Default Pattern
  • 22. Classical Pattern #1—The Default Pattern Drawbacks - Inherit both own properties added to this and prototype properties - It doesn’t enable you to pass parameters to the child constructor
  • 24. Classical Pattern #2—Rent-a-Constructor The drawback is that nothing from the prototype gets inherited A benefit is that you get true copies of the parent’s own members, and there’s no risk that a child can accidentally overwrite a parent’s property.
  • 25. Classical Pattern #3—Rent and Set Prototype + The result objects get copies of the parent’s own members and references to the parent’s reusable functionality (implemented as members of the prototype) + The child can also pass any arguments to the parent constructor - The parent constructor is called twice
  • 26. Classical Pattern #4—Share the Prototype Classical Pattern #1 inherit Changed inherit - If one child or grandchild somewhere down the inheritance chain modifies the prototype, it affects all parents and grandparents.
  • 27. Classical Pattern #5—A Temporary Constructor + The child only inherits properties of the prototype - We don’t have a reference to the original parent
  • 28. Another methods With the class keyword ECMAScript 6 introduced a new set of keywords implementing classes. Although these constructs look like those familiar to developers of class- based languages, they are not. JavaScript remains prototype-based. The new keywords include class, constructor, static, extends, and super. With Object.create ECMAScript 5 introduced a new method: Object.create(). Calling this method creates a new object. The prototype of this object is the first argument of the function: