Skip to content

Instantly share code, notes, and snippets.

@andreasonny83
Last active February 26, 2016 10:06
Show Gist options
  • Save andreasonny83/77de03c258ce811095d0 to your computer and use it in GitHub Desktop.
Save andreasonny83/77de03c258ce811095d0 to your computer and use it in GitHub Desktop.
JavaScript nested functions
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Javascript nested functions">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<a href="https://jsbin.com/viposub/edit?html,js,output">Jsbin available here</a>
<p>Result: <span id="result"></span></p>
<script id="jsbin-javascript">
var result = document.getElementById("result");
function sum(a) {
var res = a || 0;
console.log('1: ', res);
function add(b) {
res += b;
console.log('2: ', res);
return add;
}
add.get = function() {
return res;
}
return add;
}
result.innerHTML = sum(1)(1)(10)(5).get();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment