From b05af3dd440f0c453f2c7cd30073ffb970ffdfe0 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 15 Aug 2019 10:29:49 +0200 Subject: [PATCH] Fix `promise.then` inside `if` --- src/js/treemode.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/js/treemode.js b/src/js/treemode.js index 77ee3e5..644abf7 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -1499,15 +1499,19 @@ treemode._showAutoComplete = function (element) { self.autocomplete.hideDropDown(); } else if (typeof result.then === 'function') { // probably a promise - if (result.then(function (obj) { - if (obj === null) { - self.autocomplete.hideDropDown(); - } else if (obj.options) { - self.autocomplete.show(element, obj.startFrom, obj.options); - } else { - self.autocomplete.show(element, 0, obj); - } - }.bind(self))); + result + .then(function (obj) { + if (obj === null) { + self.autocomplete.hideDropDown(); + } else if (obj.options) { + self.autocomplete.show(element, obj.startFrom, obj.options); + } else { + self.autocomplete.show(element, 0, obj); + } + }) + .catch(function (err) { + console.error(err); + }); } else { // definitely not a promise if (result.options)