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.
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
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.
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
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: