0

I have 3 JQuery plugins which are similar to this

 $(function() {

        	var Plugin1/2/3 = {
                fun1:{}
                fun2:{} 
                ...
                init: function()
        		{
        			o = $.extend({}, this);
                }
         
            }

            $.fn.Plugin1/2/3 = function(){

        		return this.each(function(){
                    var obj = Object.create(Plugin1/2/3);
                    obj.init();
                });
        	}
         }

$(document).ready(function() {
   $(document).Plugin1();
   $(document).Plugin2();
   $(document).Plugin3();
});

Everywhere i have used variable o to extend. What happens is when Plugin3 is created all the objects of above two plugins gets overwritten and all information shown are of the 3rd Plugin.

I am looking for a solution to this as well as some good guides on Jquery Advance plugin creation.

Pastebin Link: http://pastebin.com/GJTEEjyt

Result: enter image description here

Thanks.

5
  • what's this var Plugin1/2/3 = {?
    – Mox Shah
    Mar 17, 2015 at 11:31
  • 1
    Because here you need a var => var o = $.extend({}, this);
    – lshettyl
    Mar 17, 2015 at 11:33
  • I have 3 plugins, Plugin1, Plugin2, Plugin3, so represented like 1/2/3.
    – Rahul Dev
    Mar 17, 2015 at 11:33
  • 1
    Rahul, LShetty may have been able to figure it out, but you've chopped too much out of the code, leaving the C out of MCVE. Mar 17, 2015 at 11:34
  • I have edited my post with full Jquery pastebin link and result.
    – Rahul Dev
    Mar 17, 2015 at 12:07

1 Answer 1

3

That's what happens when you take var for granted!

init: function() {
    var o = $.extend({}, this);
}

And re: jQuery plugin, I have been using this for a while now. Take a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.