11. Scope
Scope in a programing language controls the
visibility and lifetimes of variables and
parameters.
•
•
•
Global scope
Function scope
this
12. Falsy
The following values are falsy
o
o
o
o
o
o
false
0 (zero)
“” (empty string”)
null
undefined
NaN (not a number)
Everything else is truthy
13. Function - first class
object
Function
•
•
•
•
•
•
is an instance of Object type
can have properties
can have methods
can be stored in a variable
can be passed as parameter
can be returned from a function
15. hoisting
•
function declarations and variable
declarations are always moved (hoisted)
invisibly to the top of their containing scope
by the javascript interpreter.
•
one var statement per scope at the top
16. arguments
•
•
•
•
•
an object available within all functions
exists only inside function body
not an Array but similar
have length property
does not have Array methods like pop
17. call / apply
•
•
call is used when you want to control the
scope that will be used in the function called.
http://jsfiddle.net/rajakvk/3Yp6D/
18. closure
Definition: closure is the local variable for a
function - kept alive after the function has
returned
•
•
Garbage collection
Memory leak
19. name space
•
•
•
Name spacing is a technique employed to
avoid collisions with other objects or
variables in the global scope.
No built in support.
var AppSpace = AppSpace || {};
AppSpace.Mail = function(){};
AppSpace.Video = function(){};
20. prototype
•
•
prototype is an object from which other
objects inherit properties and methods
Every function has a prototype by default
26. Introduction
•
Patterns are proven solutions to software
development problems.
•
•
Patterns are reusable for similar problems.
Creational, Structural, Behavioural
27. What is covered here?
Singleton - Creational
Module - Structural
Decorator - Structural
Observer - Behavioural
28. Singleton Pattern
•
•
•
•
The singleton pattern is a design pattern that
is used to restrict instantiation of a class to
one object.
Namespacing, Grouping related methods
and attributes together.
Tightly coupled, Unit testing is difficult
http://jsfiddle.net/rajakvk/gv644/
29. Module Pattern
•
•
Loose definition: a way to provide both
private and public encapsulation for classes.
http://addyosmani.com/resources/essentialjs
designpatterns/book/#modulepatternjavascri
pt
31. Observer Pattern
•
•
Define a one-to-many dependency between
objects so that when one object changes
state, all its dependents are notified and
updated automatically.
http://www.dofactory.com/javascriptobserver-pattern.aspx