function getCount() {
return this.myCount++;
}
> var counter2 = getCount.bind({myCount:100});
undefined
> counter2()
100
> counter2()
101
function getCount() {
return this.myCount++;
}
> var counter2 = getCount.bind({myCount:100});
undefined
> counter2()
100
> counter2()
101
function getCounter() {
var myCount = 0;
return function() {
return myCount++;
}
}
counter = getCounter();
> counter();
0
> counter();
1
JavaScript function without defining parameters
function add() {
var result = 0;
for (var i = 0; i < arguments.length; i++) {
result = result + arguments[i];
}
return result;
}
Result :
> add(3,7,8,10)
28