1

I am creating a javascript application that will live in a library and be used on multiple sites. I am looking for it to have the following features and need some guidance on accomplishing these goals:

  • Use an iife to protect the variable scope of my application.
  • use document ready within the iife to ensure dom manipulation is available when I need.
  • However because the code lives in a library, I would like to be able to customize the code via options or other methods on a per site basis if need be, but obviously without changing the core library code. -I basically need a sound method for inheriting, overriding or customizing the library code.

I don't feel my current design will allow for this type of customization. What options do I have for achieving this? Could I somehow make this a parent class and then use prototyping on individual sites to customize as needed?

//lives in library, merely an example of structure
    (function($) {
        $(document).ready(function(){
            //establish configuration variables
            var configVars ={
                example: $('#test').attr('href'),
                two: 'a number'
            };
            //establish main operational object
            var example = {

                start: function(){
                    console.log(configVars.$one);
                    example.moveForward();
                },

                moveForward: function(){
                    console.log(configVars.two);
                }
            };
            example.start();
        });
    })(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.