main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function makeAdder(x) {

	function add(y) {
    return y + x;
  }
	
	// Return a closure
  return add; 
  
}

// We can instaniate objects with predefined properties now.
// `makeAdder(1)` will add 1 to whatever number is passed to it.
var plusOne = makeAdder(1);
// `makeAdder(10)` will add 10 to whatever number is passed to it.
var plusTen = makeAdder(10);

console.log(plusOne(3)); // 4
console.log(plusTen(3)); // 13
Native Browser JavaScript