Hi,
i'm trying to write a jQuery plugin, i have read some posts, documents
and other plugin code, but i don't understand the right standard to
write a plugin.
I found some patterns...

== example 1==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
    });
  };
})(jQuery);

== example 2==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
    });
  };
  // private function
  function functionA () {..do something..};
})(jQuery);

== example 3==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
    });
  };
  // Public function?!?
  $.fn.myPlugin.functionA () {..do something..}
})(jQuery);

== example 4==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
    });
  };

  $.extend(myPlugin.prototype, {
    functionA : function() {..do something..},
    functionB : function() {..do something..}
  }
})(jQuery);

== example 5==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
      var functionA = function () {..do something..}
    });
  };
})(jQuery);

== example 6==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      // do something
    });
  };
  $.fn.extend ({
    functionA : function () {..do something..}
  });
})(jQuery);

== example 7==
(function($) {
  $.fn.myPlugin = function(o) {
    return this.each(function() {
      new myObj();
    });
  };

  $.myObj = function () {..do something..};
  $myObj = $.myObj;
  $myObj.fn.extend = $myObj.extend = $.extend;
  $myObj.fn.extend ({
    functionA: function() {..do something..},
    functionB: function() {..do something..}
  });
  $myObj.extend ({
    functionC: function() {..do something..}
  });
})(jQuery);


Which is the right plugin writting way?
I think that the last example is well done... but i don't understand
this line $myObj.fn.extend = $myObj.extend = $.extend; and the
differents between $myObj.fn.extend and $myObj.extend .. public or
private function? the first is for public function?

Please may you help me?

Many thanks
bye
Max

Reply via email to