Last active
February 26, 2016 10:06
-
-
Save andreasonny83/77de03c258ce811095d0 to your computer and use it in GitHub Desktop.
JavaScript nested functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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