GithubHelp home page GithubHelp logo

jquery-plugin-boilerplate's Issues

Duplication

Although this one of the most sane ways of doing jQuery plugins, there is duplication there for the getters, what do you think of another convention by using get prefix in names of getters so that you automatically introspect and export them automatically instead of retyping it in the getters ?

Methods that require a return value are not returned, instead, as written, method return jQuery object

Greetings, using your template, we needed a method to return values.
For example,

var myvalue = $('#foo').myPlugin('methodThatShouldReturnValue') ;

As written here, this is not allowing the return value in methodThatShouldReturnValue to pass through:

 // Invoke the specified method on each selected element
                return this.each(function() {
                    var instance = $.data(this, 'plugin_' + pluginName);
                    if (instance instanceof Plugin && typeof instance[options] === 'function') {
                        instance[options].apply(instance, Array.prototype.slice.call(args, 1));
                    }
                });

It does not allow return value of the method to be returned, instead 'return this.each...' is only return jQuery object.

I've altered it like this, but perhaps you have a more elegant solution:

 // Invoke the speficied method on each selected element
                var results ;
                 this.each(function() {
                    var instance = $.data(this, 'plugin_' + pluginName);
                    if (instance instanceof Plugin && typeof instance[options] === 'function') {
                        results = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
                    }
                });
              return results ;

Note, in our plugin, that method is only applied to one id on the dom, not multiple.

In the case of multiple return values required, that code could be written like this:

 // Invoke the speficied method on each selected element
                var results = [] ;
                 this.each(function() {
                    var instance = $.data(this, 'plugin_' + pluginName);
                    if (instance instanceof Plugin && typeof instance[options] === 'function') {
                        results.push( instance[options].apply(instance, Array.prototype.slice.call(args, 1)) ) ;
                    }
                });
              return results ;

Again, perhaps you have a preferred way to rewrite the code to account for both scenarios and return appropriately.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.