Need help for creating a simple javascript library

Hi,

I found a lots of discussion about javascript in the web. But there are only few discussions about the guideline for creating a new javascript library.
In one of my project I have used jQuery and created some javascript functions which uses jQuery. Now I want to create a javascript library for those function.
The target is - users who want to use the features implemented by the javascript functions will use it as a library/api (I don’t know what is the right word here).
Can anybody please guide me how I will proceed to achieve this goal?

Thanks in advance for your time.

Hi,

Maybe you mean “plugin”?

This involves extending jQuery to create reusable components that can be used on any web page.

You can do this by extending $.fn (an alias for jQuery.prototype) with a function of your own. This function will then be available just like any other jQuery object method.

For example, if you wanted to write a plugin to add random amounts of padding to an element, you could do it like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Simple plugin example</title>
    <style>
      div{ 
        margin: 50px;
        background: blue;
      }
    </style>
  </head>
  <body>
    <div>Here's a nice div element</div>
    <div>Here's another one</div>
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script>
      $.fn.animatePadding= function() {
        var randomPadding = Math.floor(Math.random()*101);
        this.animate({ 'padding' : randomPadding });
        return this;
      };

      $("div").each(function(){
        $(this).animatePadding();
      });
    </script>
  </body>
</html>

I wrote a simple blog post on this a while back.
Here’s another good link: http://www.sitepoint.com/how-to-develop-a-jquery-plugin/

Does that help?