{"ScriptPreparationCode":"function debounce1a(func, wait, immediate) {\r\n let timeout, args, context, timestamp, result;\r\n\r\n const later = function() {\r\n const last = now() - timestamp;\r\n\r\n if (last \u003C wait \u0026\u0026 last \u003E= 0) {\r\n timeout = setTimeout(later, wait - last);\r\n } else {\r\n timeout = null;\r\n if (!immediate) {\r\n result = func.apply(context, args);\r\n if (!timeout) context = args = null;\r\n }\r\n }\r\n };\r\n \r\n \tconst debounced = function() {\r\n context = this;\r\n args = arguments;\r\n timestamp = now();\r\n \r\n let callNow = immediate \u0026\u0026 !timeout;\r\n if (!timeout) timeout = setTimeout(later, wait);\r\n if (callNow) {\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n\r\n return result;\r\n };\r\n\r\n return debounced;\r\n};\r\n\r\nfunction debounce1b(func, wait, immediate) {\r\n let timeout, args, context, timestamp, result;\r\n\r\n const later = function() {\r\n const last = now() - timestamp;\r\n\r\n if (last \u003C wait \u0026\u0026 last \u003E= 0) {\r\n timeout = setTimeout(later, wait - last);\r\n } else {\r\n timeout = null;\r\n if (!immediate) {\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n }\r\n };\r\n\r\n const debounced = function() {\r\n context = this;\r\n args = arguments;\r\n timestamp = now();\r\n\r\n if (immediate \u0026\u0026 !timeout) {\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n\r\n if (!timeout) timeout = setTimeout(later, wait);\r\n \r\n return result;\r\n }\r\n \r\n return debounced;\r\n};\r\n\r\nfunction debounce1c(func, wait, immediate = false) {\r\n let timeout, context, args, timestamp, result;\r\n\r\n const later = function() {\r\n const last = now() - timestamp;\r\n\r\n if (last \u003C wait \u0026\u0026 last \u003E= 0) {\r\n timeout = setTimeout(later, wait - last);\r\n } else {\r\n timeout = null;\r\n if (!immediate) {\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n }\r\n };\r\n\r\n const debounced = function() {\r\n context = this;\r\n args = arguments;\r\n\r\n if (immediate) {\r\n if (!timestamp || (now() - timestamp) \u003E= wait) {\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n } else {\r\n if (!timeout) timeout = setTimeout(later, wait);\r\n }\r\n timestamp = Date.now();\r\n\r\n return result;\r\n };\r\n\r\n return debounced;\r\n};\r\n\r\nfunction debounce2a(func, wait, immediate) {\r\n let timeout, result, context, args;\r\n let last = -Infinity;\r\n\r\n const later = function () {\r\n timeout = null;\r\n exec(context, args);\r\n if (!timeout) context = args = null;\r\n };\r\n\r\n const exec = function (context, args) {\r\n const now = now();\r\n const delta = now - last;\r\n if (immediate) last = now;\r\n if (delta \u003C wait \u0026\u0026 delta \u003E= 0) {\r\n if (!immediate) timeout = setTimeout(later, wait - delta);\r\n } else {\r\n result = func.apply(context, args);\r\n }\r\n };\r\n\r\n \tconst leading = function (params) {\r\n exec(this, params);\r\n return result;\r\n };\r\n\r\n const trailing = function (params) {\r\n last = now();\r\n context = this;\r\n args = params;\r\n if (!timeout) timeout = setTimeout(later, wait);\r\n return result;\r\n };\r\n\r\n const debounced = immediate ? leading : trailing;\r\n\r\n return debounced;\r\n};\r\n\r\nfunction debounce2b(func, wait, immediate) {\r\n let timeout, result, context, args;\r\n let last = -Infinity;\r\n\r\n const later = function() {\r\n timeout = null;\r\n exec(context, args);\r\n if (!timeout) context = args = null;\r\n };\r\n\r\n const exec = function(context, args) {\r\n const now = now();\r\n const delta = now - last;\r\n\r\n \tif (immediate) last = now;\r\n if (delta \u003C wait \u0026\u0026 delta \u003E= 0) {\r\n if (!immediate) timeout = setTimeout(later, wait - delta);\r\n } else {\r\n result = func.apply(context, args);\r\n }\r\n };\r\n\r\n const debounced = function() {\r\n if (immediate) {\r\n exec(this, arguments);\r\n } else {\r\n last = now();\r\n context = this;\r\n args = arguments;\r\n if (!timeout) timeout = setTimeout(later, wait);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n return debounced;\r\n}\r\n\r\nfunction debounce2c(func, wait, immediate) {\r\n let timeout, result, context, args;\r\n let last = -Infinity;\r\n\r\n const exec = function() {\r\n const now = Date.now();\r\n const delta = now - last;\r\n\r\n if (immediate) last = now;\r\n if (delta \u003C wait \u0026\u0026 delta \u003E= 0) {\r\n if (!immediate) timeout = setTimeout(exec, wait - delta);\r\n } else {\r\n timeout = null;\r\n result = func.apply(context, args);\r\n context = args = null;\r\n }\r\n };\r\n\r\n const leading = function(params) {\r\n context = this;\r\n args = params;\r\n exec();\r\n return result;\r\n };\r\n\r\n const trailing = function(params) {\r\n last = Date.now();\r\n context = this;\r\n args = params;\r\n if (!timeout) timeout = setTimeout(exec, wait);\r\n return result;\r\n };\r\n\r\n const debounced = immediate ? leading : trailing;\r\n\r\n return debounced;\r\n};\r\n\r\nfunction debounce2d(func, wait, immediate) {\r\n let timeout, result, context, args;\r\n let last = 0;\r\n\r\n const exec = function() {\r\n const now = now();\r\n const delta = now - last;\r\n if (immediate) last = now;\r\n\r\n if (delta \u003C wait \u0026\u0026 delta \u003E= 0) {\r\n if (!immediate) timeout = setTimeout(exec, wait - delta);\r\n } else {\r\n func.apply(context, args);\r\n timeout = context = args = null;\r\n }\r\n };\r\n\r\n const leading = function() {\r\n context = this,\r\n args = arguments;\r\n\r\n exec();\r\n };\r\n\r\n const trailing = function() {\r\n last = now();\r\n context = this,\r\n args = arguments;\r\n\r\n if (!timeout) timeout = setTimeout(exec, wait);\r\n };\r\n\r\n const debounced = (immediate) ? leading : trailing;\r\n\r\n return debounced;\r\n};\r\n\r\n/**************************************************/\r\n\r\nvar now = Date.now || function() {\r\n return new Date().getTime();\r\n};\r\n\r\nvar fn = function() {},\r\n\tdb_underscore_144 = underscore144.debounce(fn, 100),\r\n db_underscore_160 = underscore160.debounce(fn, 100),\r\n db_underscore_183 = underscore183.debounce(fn, 100),\r\n db_underscore_edge = underscoreEdge.debounce(fn, 100),\r\n db_lodash_edge = lodashEdge.debounce(fn, 100),\r\n db1a = debounce1a(fn, 100),\r\n db1b = debounce1b(fn, 100),\r\n db1c = debounce1c(fn, 100),\r\n db2a = debounce2a(fn, 100),\r\n db2b = debounce2b(fn, 100),\r\n db2c = debounce2c(fn, 100),\r\n db2d = debounce2d(fn, 100);","TestCases":[{"Name":"Underscore 1.4.4","Code":"db_underscore_144();","IsDeferred":false},{"Name":"Underscore 1.6.0","Code":"db_underscore_160();","IsDeferred":false},{"Name":"Underscore 1.8.3","Code":"db_underscore_183();","IsDeferred":false},{"Name":"Underscore Edge","Code":"db_underscore_edge();","IsDeferred":false},{"Name":"Lodash Edge","Code":"db_lodash_edge();","IsDeferred":false},{"Name":"Debounce #1a","Code":"db1a();","IsDeferred":false},{"Name":"Debounce #1b","Code":"db1b();","IsDeferred":false},{"Name":"Debounce #1c","Code":"db1c();","IsDeferred":false},{"Name":"Debounce #2a","Code":"db2a();","IsDeferred":false},{"Name":"Debounce #2b","Code":"db2b();","IsDeferred":false},{"Name":"Debounce #2c","Code":"db2c();","IsDeferred":false},{"Name":"Debounce #2d","Code":"db2d();","IsDeferred":false}]}