1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
[references]
http://msdn.microsoft.com/en-us/library/ie/d1et7k7c%28v=vs.94%29.aspx
[data types]
- primitive
string, number boolean
- composite (reference)
object, array
rvalues: new Object(), Object(), function() {}, {}
rvalues: [], new Array(), Array()
- special
null, undefined
note: null is not 0, does not have type, undefined is a string
[anonymous functions]
wrapping code inside of 'function() { code } ()' is handy for creating a
namespace for your code and restricting scope, since js essentially has
a global and function scope, we don't want to pollute and cause collisons
[closures]
in JavaScript, if you use the function keyword inside another function, you are
creating a closure. if a function containing function f returns that function,
that variable points to f and also to the closure, unlike C, where stack frame
would get destroyed, so f has access to variables/object in the context it was
defined in
- what about function returning a function
that's a good way to leverage closures!
['this' and 'prototype' object and the 'new']
- every object has a prototype object
- the keyword 'this' refers to the object context within which the
the function is executing
- protype is used for templating, it provides access to members of an object,
when function is assigned to this object, only 1 copy exists, it is memory
efficient, also we get expected behavior when overriding that function
- 'new' changes meaning of a function, upon invocation, function is ran in blank
object context
|