JavaScript
JavaScript
Enter the Dragon
Most misunderstood language
You have no choice
…but you have plenty of options
JavaScript
JavaScript   human body
“If you have a body, you are an athlete”
           Bill Bowerman, co-founder of Nike.
If you code for the Web,
you are a JavaScript Developer
Control
Why you “unfit”?
Why your JavaScript sucks?
“This is not important”
“I don’t need it any more, it’s XXI century”
           “I am good enough!”
       “It’s way too complicated”
        “I don’t have time for this”
Kyle Maynard — MMA fighter
Kyle Maynard — MMA fighter
Kyle Maynard — MMA fighter




Excuses… Let’s hear yours again
There are no shortcuts
“Those who are unaware
 they are walking in darkness
 will never seek the light.”
 Bruce Lee
Six essential bits
Six pack
1
Types & type coercion
object
 number
  string
 boolean
   null
undefined
5 - "4"
5 + "4"
+!{}[true]
+[1]
+[1, 2]
7 - "a"
7 / 0
…
2 Operators,
especially “+” & “==”
5 + "4"
5 + null
4 == "4.00"
null == undefined
0 == false
0 == null
null == false
typeof null == "object"
typeof function () {} == "function"
3
Objects & primitives
var a = "string";
alert(a.length);
a.t = 3;
alert(a.t);
4
Functions & constructors
function f() {};

var a   =   f
            ,
    b   =   f(),
    c   =   new f ,
    d   =   f(f);
5
Closures
function add(a) {
    return function (b) {
         return a + b;
    };
}

add(3)(4) == 7
6
Prototype
Prototypes in JavaScript
      in 5 minutes
function f() {};
                   f   P
function f() {};
f.prototype.x = 3;   f   P   x: 3
function f() {};
f.prototype.x = 3;   f   P   x: 3

var a = new f;

                     a
function f() {};
f.prototype.x = 3;    f     P   x: 3

var a = new f;
a.x = 2;
a.y = 1;              a
                     x: 2
                     y: 1
function f() {};
f.prototype.x = 3;    f     P   x: 3

var a = new f;
a.x = 2;
a.y = 1;              a     b
var b = new f;       x: 2
                     y: 1
function f() {};
f.prototype.x = 3;      z: 0   P2    f     P   x: 3

var a = new f;
a.x = 2;
a.y = 1;                             a     b
var b = new f;                      x: 2
f.prototype = {z: 0};               y: 1
function f() {};
f.prototype.x = 3;      z: 0   P2    f     P   x: 3

var a = new f;
a.x = 2;
a.y = 1;                       c     a     b
var b = new f;                      x: 2
f.prototype = {z: 0};               y: 1
var c = new f;
function f() {};
f.prototype.x = 3;      z: 0   P2    f     P   x: 3

var a = new f;
a.x = 2;
a.y = 1;                       c     a     b
var b = new f;                      x: 2
f.prototype = {z: 0};               y: 1
var c = new f;

               b.constructor == f
            c.constructor == Object
I didn’t get it…
Function.constructor == Function
Nobody knows what to do
http://www.udel.edu/anthro/neitzel/supplemental%20sportsS09.htm
Different goals
demand different approaches
Form always follows the function
http://www.flickr.com/photos/sgroi/3228398172/
http://en.wikipedia.org/wiki/Hercules_of_the_Forum_Boarium
http://www.flickr.com/photos/stebbz/2451346427/
Thank You
“A wise man can learn more from
 a foolish question
 than a fool can learn from
 a wise answer.”
Bruce Lee
“If you spend too much time
 thinking about a thing,
 you’ll never get it done.”
 Bruce Lee

JavaScript: enter the dragon