Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes getter methods created when plugins are initialized. #20

Merged
merged 1 commit into from
Feb 19, 2012
Merged

Fixes getter methods created when plugins are initialized. #20

merged 1 commit into from
Feb 19, 2012

Conversation

deefour
Copy link
Contributor

@deefour deefour commented Feb 7, 2012

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

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
alexgorbatchev added a commit that referenced this pull request Feb 19, 2012
Fixes getter methods created when plugins are initialized.
@alexgorbatchev alexgorbatchev merged commit f7b74dd into alexgorbatchev:master Feb 19, 2012
@alexgorbatchev
Copy link
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants