From 2133129a7419b446d4c1397625fcfb5fb9a7d9dd Mon Sep 17 00:00:00 2001 From: "Braden M. Kelley" Date: Thu, 1 May 2014 08:54:32 -0700 Subject: [PATCH] keyword `this` inside closures referring to wrong object --- select2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/select2.js b/select2.js index 682baa88..c5d1eca6 100644 --- a/select2.js +++ b/select2.js @@ -1076,7 +1076,7 @@ the specific language governing permissions and limitations under the Apache Lic */ // abstract monitorSource: function () { - var el = this.opts.element, observer; + var el = this.opts.element, observer, self = this; el.on("change.select2", this.bind(function (e) { if (this.opts.element.data("select2-change-triggered") !== true) { @@ -1106,7 +1106,7 @@ the specific language governing permissions and limitations under the Apache Lic // IE8-10 (IE9/10 won't fire propertyChange via attachEventListener) if (el.length && el[0].attachEvent) { el.each(function() { - this.attachEvent("onpropertychange", this._sync); + this.attachEvent("onpropertychange", self._sync); }); } @@ -1115,7 +1115,7 @@ the specific language governing permissions and limitations under the Apache Lic if (observer !== undefined) { if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; } this.propertyObserver = new observer(function (mutations) { - mutations.forEach(this._sync); + mutations.forEach(self._sync); }); this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false }); }