From 32f0ebbe6177040a846dc42e39cfb8e87f3427e3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 20 May 2013 22:53:27 -0700 Subject: [PATCH] Avoid issues with Titanium, `clearTimeout`, and an `undefined` timer id. Former-commit-id: 18813fcebbab5185164c236a647b0b6436d495ff --- build.js | 6 +++--- lodash.js | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build.js b/build.js index c8e6a3822..eedbff1fa 100755 --- a/build.js +++ b/build.js @@ -2210,7 +2210,7 @@ ' var args,', ' result,', ' thisArg,', - ' timeoutId;', + ' timeoutId = null;', '', ' function delayed() {', ' timeoutId = null;', @@ -2567,8 +2567,8 @@ ' var args,', ' result,', ' thisArg,', - ' timeoutId,', - ' lastCalled = 0;', + ' lastCalled = 0,', + ' timeoutId = null;', '', ' function trailingCall() {', ' lastCalled = new Date;', diff --git a/lodash.js b/lodash.js index e00d47118..6de91505d 100644 --- a/lodash.js +++ b/lodash.js @@ -4639,8 +4639,8 @@ var args, result, thisArg, - timeoutId, callCount = 0, + timeoutId = null, trailing = true; function delayed() { @@ -4660,6 +4660,9 @@ return function() { args = arguments; thisArg = this; + + // avoid issues with Titanium and `undefined` timeout ids + // https://github.com/appcelerator/titanium_mobile/blob/3_1_0_GA/android/titanium/src/java/ti/modules/titanium/TitaniumModule.java#L185-L192 clearTimeout(timeoutId); if (leading && ++callCount < 2) { @@ -4868,9 +4871,9 @@ var args, result, thisArg, - timeoutId, lastCalled = 0, leading = true, + timeoutId = null, trailing = true; function trailingCall() {