let newObj = {
    total:  65,
    increment: 1
}

const incrementTotal = function(obj, val){
    obj.increment = val;
    return function(){
        console.log(obj.total);
        obj.total = obj.total + obj.increment;
        console.log(obj.total);

    };
};
const incBy1 = incrementTotal(newObj, 1);
const incBy2 = incrementTotal(newObj, 2);
//  will be incremented by 10 
const incBy10 = incrementTotal(newObj, 10);


In this case, the result in each execution will be incremented by 10 because in the last line we have written 10 that will be regret 2 previous lines where we have written increment by 1 and increment by 2...
by Luka Tatarishvili
4 years ago
JavaScript
objects
0
Pro tip: use ```triple backticks around text``` to write in code fences