Created
February 23, 2016 19:53
-
-
Save andreasonny83/636d73920f68abc98033 to your computer and use it in GitHub Desktop.
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
function test(val) { | |
var n = val || 0; | |
document.write(n, '<br>'); | |
function add(addN) { | |
addN = addN || 0; | |
document.write('[add ', addN, ']<br>'); | |
n += addN; | |
document.write(n, '<br>'); | |
return this; | |
} | |
function times(timesN) { | |
timesN = timesN || 1; | |
document.write('[times ', timesN, ']<br>'); | |
n *= timesN; | |
document.write(n, '<br>'); | |
return this; | |
} | |
function get() { | |
document.write('[get]<br>', n); | |
return this; | |
} | |
return { | |
add: add, | |
times: times, | |
get: get | |
}; | |
} | |
test(2).add(3).times(2).get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment