Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to handle events with a jQuery plugin?

Hi,

I am working on my own jquery plugin, given this architecture:

(function($){
    'use strict';
    $.fn.pluginName = function(options) {

        var defaultOptions = {
        };  

        var params = $.extend(defaultOptions, options);

        function pluginName(element) {
            this.$element = element;
            this.init();
        }

        $.extend(easyParallax.prototype, {

            init: function() {
                functionA();
                if (functionC()) {
                    functionB();
                }
            },

            functionA: function() {},
            functionB: function() {},
            functionC: function() {},
            destroy: function() {}

        });

        return this.each(function() {

            new pluginNAme($(this));
        });
    }
})(jQuery);

What I would like here:

  1. the functionA to execute only one time at the initialisation, not at every instance of "return this.each(function() {". But the var calculated in the function A should be available in other function ( B and C)
  2. on every window scroll event, having the functionA() running one time + functionB() running for every instance of each.