The document discusses JavaScript as a language. It notes that JavaScript implements ECMAScript and is object-oriented without classes. Objects are dynamic collections of named properties that can be added, removed or updated. JavaScript also has loose typing, lambdas, native and host objects, and prototypical inheritance. Good parts of the language include lambdas, dynamic objects, loose typing and object literals, while bad parts include global variables, addition/concatenation with +, semicolon insertion, typeof, with and eval, and comparisons with == and !=. The document then covers general patterns in JavaScript including minimizing globals, implied globals, the single var pattern, namespacing, and more.
2. JavaScript
as
a
language
• Implementa3on
of
ECMASCRIPT
• Object
oriented
• No
Classes
• Dynamic
Objects
-‐
collec3on
of
named
proper3es.
You
can
add,
remove,
update
its
members.
• Loose
typing
• lambdas
• Na3ve
and
host
objects
-‐
Environment
specific
• Prototypical
inheritance
3. Good
Parts
• Lambda
• Dynamic
objects
• Loose
typing
• Object
literals
4. Bad
Parts
• Global
Variables
• +
adds
and
concatenates
• Semicolon
inser3on
• typeof
• with
and
eval
• ==
and
!=
• false,
null,
undefined,
NaN
32. CREATIONAL
Builder
constructs
complex
objects
by
separa3ng
construc3on
and
representa3on
Factory
Method
creates
objects
without
specifying
the
exact
class
to
create
Singleton
restricts
object
crea3on
for
a
class
to
only
one
instance
STRUCTURAL
Decorator
dynamically
adds/overrides
behavior
in
an
exis3ng
method
of
an
object
Facade
provides
a
simplified
interface
to
a
large
body
of
code
BEHAVIORAL
Chain
of
responsibility
delegates
commands
to
a
chain
of
processing
objects
Command
creates
objects
which
encapsulate
ac3ons
and
parameters
Mediator
allows
loose
coupling
between
classes
by
being
the
only
class
that
has
detailed
knowledge
of
their
methods
Observer
is
a
publish/subscribe
paSern
which
allows
a
number
of
observer
objects
to
see
an
event
38. Prolifera3on
of
MV*
frameworks
• Rich
internet
single
page
applica3ons
• Data
Binding
• Client
side
templates
• Client-‐Centric
or
Server-‐Centric-‐
that
is
the
ques3on.
39. • Minify,
concatenate,
compress
• Load
scripts
at
the
end
of
pages
• Sta3c
code
analysis
using
Jslint/Jshint
• Tes3ng
your
code
–
Jasmine,
Phantomjs
etc