{"ScriptPreparationCode":"const data = [\r\n {a: 1, b: 10},\r\n {a: 2, b: 9},\r\n {a: 3, b: 8},\r\n {a: 4, b: 7},\r\n {a: 5, b: 6},\r\n {a: 6, b: 5},\r\n {a: 7, b: 4},\r\n {a: 8, b: 3},\r\n {a: 9, b: 2},\r\n {a: 10, b: 1},\r\n]\r\n\r\nwindow.fns = []\r\n\r\nfor (let c = 0; c \u003C data.length; c\u002B\u002B) {\r\n const {a, b} = data[c];\r\n const fn = function() {\r\n return \u0060${a} \u002B ${b} \u002B ${c} = ${a \u002B b \u002B c}\u0060\r\n }\r\n fns.push(fn)\r\n}\r\n\r\n\r\nclass DataItem {\r\n a\r\n b\r\n\r\n constructor(a, b, c) {\r\n this.a = a\r\n this.b = b\r\n }\r\n\r\n calc(c) {\r\n return \u0060${this.a} \u002B ${this.b} \u002B ${c} = ${this.a \u002B this.b \u002B c}\u0060\r\n }\r\n}\r\n\r\nwindow.fnCalls = []\r\n\r\nfor (let c = 0; c \u003C data.length; c\u002B\u002B) {\r\n const { a, b } = data[c]\r\n const dataItem = new DataItem(a, b)\r\n fnCalls.push([dataItem.calc, dataItem, [c]])\r\n}","TestCases":[{"Name":"Call separate closures for each calc","Code":"fns.forEach(fn =\u003E console.log(fn()))","IsDeferred":false},{"Name":"Call the same calc function with different arguments","Code":"fnCalls.forEach(([fn, thisArg, args] = call) =\u003E\r\n console.log(fn.apply(thisArg, args))\r\n)","IsDeferred":false}]}