August 18, 2017

Closure scope vs. Object scope

function outer() {
	var one = 1;
	var two = 2;

	return function inner() {
		return one + two;
	};
}

const three = outer();

three(); // 3

And an illustration of a simple object:

const obj = {
	one: 1,
	two: 2,
};

function three(outer) {
	return outer.one + outer.two;
}

three(obj); // 3