Is it possible to create a namespace in jQuery?

后端 未结 8 919
星月不相逢
星月不相逢 2020-11-27 13:52

YUI has a nice way of creating a namespace for your methods etc. in javascript.

Does jQuery have anything similiar?

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 14:05

    Depending on what you're trying to do, jQuery's plugin architecture may be what you're looking for:

    $.fn.myPlugin = function() {
      return $(this).each(function() {
        // do stuff
      });
    };
    

    or ...

    $.fn.myPlugin = function() {
      var myNamespace = {
        // your stuff
      };
    };
    

    really it depends on what you're trying to do.

    http://docs.jquery.com/Plugins/Authoring

提交回复
热议问题