Skip to content

misleading example about retrieval of widget instance through data() #515

Closed
@teo1978

Description

@teo1978

http://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 name as the key

That vaguely suggests that the plugin name is used as the key, and one may wonder whether the namespace is included, and how it is joined to the plugin name

The code example seems to clear any possible dubt:

var bar = $( "<div />")
    .appendTo( "body" )
    .progressbar()
    .data( "progressbar" );

The namespace is omitted. And that's wrong. That will never work.

The example was so clear and unambiguous (but wrong) that it led me to think that there was an actual bug in the software, which I wrongly reported.
http://bugs.jqueryui.com/ticket/10123#comment:2

The namespace is infact needed, and it must be joined to the plugin name with a hyphen.

That should be stated explicitely, and the example code fixed:

var bar = $( "<div />")
    .appendTo( "body" )
    .progressbar()
    .data( "nmk-progressbar" );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions