setTimeout & useSumFunction

by John Wick

JavaScript

window.sample_obj = "Test";
var getSumFunction = function () {
		var currentSegment = { "obj" : "val", "sample_obj" : "Test Inside" };
    return function sumClosure (var_entry) {
    		//sum += 10;
        console.log("this.sample_obj ", this.sample_obj);
        /* if (typeof currentSegment["sum"] === "undefined") {
          currentSegment["sum"] = 0;
        }
        currentSegment["sum"] += 10;
        if (var_entry) {
          currentSegment.obj = "edited";
        }
        console.log("The sum is bla bla ", currentSegment); */
    };
}

var useSumFunction = getSumFunction();

useSumFunction();

setTimeout(function() {
	useSumFunction("sample");
  console.log("This is last");
}, 100);

console.log("first");

// setTimeout(function() {
// 	useSumFunction("sample");
//   console.log("This is not last");
// }, 10);

// setTimeout(function() {
// 	useSumFunction("sample");
//   console.log("This is not last 1");
// }, 10);

// useSumFunction();
// useSumFunction();
// useSumFunction();
// useSumFunction();