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

misleading example on access of widget instance through .data() #796

Open
jerrylammel opened this issue Jul 23, 2020 · 0 comments
Open

misleading example on access of widget instance through .data() #796

jerrylammel opened this issue Jul 23, 2020 · 0 comments

Comments

@jerrylammel
Copy link

jerrylammel commented Jul 23, 2020

https://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/#the-widget-factory-under-the-hood

When a plugin instance is created, it is stored on the original DOM element using jQuery.data, with the plugin's full name (the plugin's namespace, plus a hyphen, plus the plugin's name) as the key.

var bar = $( "<div />")
    .appendTo( "body" )
    .progressbar()
    .data( "nmk-progressbar" );
 
// Call a method directly on the plugin instance.
bar.option( "value", 50 );
 
// Access properties on the plugin instance.
alert( bar.options.value );

I think the example given is misleading even with the namespace specified in accessing jQuery.data,
i.e. .data("nmk-progressbar").

The issue is that .progressbar() actually creates an instance of the Progressbar Widget of jQuery UI https://api.jqueryui.com/progressbar/#quick-nav rather than one of the plugin nmk-progressbar
built with Widget Factory.

The code snippet happens to make it being able to access the plugin instance of nmk-progressbar
by using the key "nmk-progressbar", which does run successfully but incorrect in meaning.

As considering the context in the article is with jQuery UI Widget Factory, this suggests audiences
that it is a way, using .progressbar(), to make an instance of the plugin nmk-progressbar.

I hope I am not wrong and expect for comments from anyone experienced.
Thanks ^_^

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

No branches or pull requests

2 participants