Skip to content

Public methods on multiple objects #2

@captainfromspace

Description

@captainfromspace

Hi,

I've noticed an issue with this plugin patten. Public methods doesn't work when you pass a selector that target multiple objects. Below is an example where we create two instances of the plugin, first on a single element var single = new myPluginName('.js-single');, and then on multiple elements var multiple = new myPluginName('.js-multiple');.

If I trigger the public update() method on both of those instances, an error will be thrown on the multiple since the plugin returns an array containing all the objects for multiple.
https://jsfiddle.net/jLeu98oq/

Sure, we could loop through all the objects and trigger the update – https://jsfiddle.net/jLeu98oq/2/ – but isn't there a nicer solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions