Skip to content

Instantly share code, notes, and snippets.

@andreasonny83
Created February 23, 2016 19:53
Show Gist options
  • Save andreasonny83/636d73920f68abc98033 to your computer and use it in GitHub Desktop.
Save andreasonny83/636d73920f68abc98033 to your computer and use it in GitHub Desktop.
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