Skip to content

Commit 0a805ee

Browse files
author
Deefour
committed
Fixes getter methods created when plugins are initialized.
Because the following function definition is not wrapped in a closure self[name] = function() { return plugin; }; `plugin`'s scope is the `TextExt.initPlugins` function. Because of this, on each iteration of the list of plugins to create the getter methods in `TextExt`, the return value of all created methods will be the last value of `plugin` and not the value of `plugin` from when the function was defined for each. Wrapping the function definition in a closure fixes this issue. As an explicit example: Previously, when instantiating a new `textext(...)` instance and defining the `plugins` option as plugins: 'autocomplete arrow' All 3 of the following would return the `TextExtArrow` instance $('...').textext()[0].ie9(); $('...').textext()[0].autocomplete(); $('...').textext()[0].arrow(); After they closure from this changeset is applied, they return their expected plugin instances $('...').textext()[0].ie9(); // TextExtIE9Patches $('...').textext()[0].autocomplete(); // TextExtAutocomplete $('...').textext()[0].arrow(); // TextExtArrow
1 parent 1786e49 commit 0a805ee

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/js/textext.core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@
802802
if(plugin)
803803
{
804804
self._plugins[name] = plugin = new plugin();
805-
self[name] = function() { return plugin; };
805+
self[name] = (function(plugin) {
806+
return function(){ return plugin; }
807+
})(plugin);
806808
initList.push(plugin);
807809
$.extend(true, plugin, self.opts(OPT_EXT + '.*'), self.opts(OPT_EXT + '.' + name));
808810
}

0 commit comments

Comments
 (0)