Part of the JavaScript training series offered by Bitovi. Full course schedule is available here: http://blog.bitovi.com/free-weekly-online-javascript-training/
3. var sum = function( x , y ){
return (++x) +
(++y.val)
},
a = 1,
b = {val : 2},
c = sum( a, b);
Types as Arguments
WINDOW
sum fn
a
b
c 5
1
2
sum(a,b
)
x
y
1
PROTOTYPE
val
2
3
17. Exercise
Build a tag library that creates elements of the following types in the
least LOC: a, div, span, form, h1, h2, h3, h4.
Example usage:
var h1 = make.h1();
h1.innerHTML = 'Hello World';
document.body.appendChild(h1);
var a = make.a();
a.href= 'http://canjs.com';
a.innerHTML = 'CanJS';
document.body.appendChild(a);
HINTS:
• Code is ‘built’ one statement at a time.
• document.createElement('h1') – creates and returns an 'h1' element.
I think the key to JavaScript is really understanding what’s going on in memory. And the key to understanding what’s going on in memory is understanding
what JS’s basic data types look like in memory and how JS’s operators are used to manipulate those data structures.
Every time you create a function, a new closure is created