Wednesday, June 26, 2013

Extending jQuery with jQuery.Extend

We all know that jQuery is a great JavaScript framework. It’s provide lots of functionalities and most used framework in programming world. But sometimes we need a functionality that does not provided by jQuery by default. At that time we need to extend jQuery. We can extend jQuery with jQuery.Extend  Method. You can get complete information from the following link.

http://api.jquery.com/jQuery.extend/

It merges the contents of two or more objects together into the first object.

Example of jQuery Extend:


Let’s take an example for jQuery.Extend so you can understand it better. In this example we will extend jQuery to print array. Following is a code for that.

<script type="text/javascript">
    $(document).ready(
        function () {
            var car = new Array();
            car[0] = "Audi";
            car[1] = "Volvo";
            car[2] = "BMW";
            $.printArray(car);
        }
    );
    jQuery.extend({
        printArray: function( array) {
            jQuery.each(array, function (index, item) {
                console.log(item);
            });
        }        
    });
</script>

Here in the above code I have created a array in document.ready function of jQuery and then I have used jQuery.Extend method to extend jQuery and print array. In print Array method I have used console.log to print array item.

Now when you run this example in Internet explorer developer tool bar. You will get array output as expected.

jQueryExtendExample

You can see it’s very easy to extend jQuery with jQuery.Extend. That’s it. Hope you liked it. Stay tuned for more..

Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews