my favorite

2011/05/17

function terminology

Notes about Javascript Patters Chapter 4: Function

named function expression

// named function expression
var add = function add(a, b) {
return a + b;
};


// function expression, a.k.a. anonymous function
var add = function (a, b) {
return a + b;
};

The only difference of above 2 function expressions are name property of function

// named function expression
var add = function add(a, b) {
return a + b;
};

> add.name
"add"

// function expression, a.k.a. anonymous function
var add = function (a, b) {
return a + b;
};

> add.name
""



// function declarations
function foo() {
// function body goes here
}

The difference between function expressions and function declarations are not that obvious, function expressions need tailing semicolon while function declarations don't

No comments:

BIO

Taipei, GuTing, Taiwan

huang47 | personal

huang47 | personal