The method of extending and expanding functions under jquery (a typical example of anonymous function use) _jquery

Source: Internet
Author: User
Tags reserved
I chose jquery, the most important is its thinking "write Less,do more", because I am a picky person, the previous written code, will be turned out from time to time to see if there can be streamlined, optimized place. One is the promotion of continuous learning, and secondly can be new ideas, technology applied to the inside.
The jquery plug-in writing, has been introduced before, there are many examples on the Internet. Here's a quick way to do this, mainly for shorthand, see the following code:
<script type= "Text/javascript" src= "Jquery-1.4.2.js" ></script>
Copy Code code as follows:

<script type= "Text/javascript" >
jquery plug-in notation (requires incoming action object)
;(function ($)
{
Pi_testplugin is the plug-in name and is the action object of the plug-in
In order not to repeat with other plugin names, I use plugin's abbreviated PI_ to define the plugin object prefix
$.fn. pi_testplugin=
{
Basic information for this plugin
info:{
Name: "Testplugin",
Ver: "1.0.0.0",
Corp: "Lzhdim",
Author: "Lzhdim",
Date: "2010-01-01 08:00:00",
Copyright: "Copyright @ 2000-2010 Lzhdim Technology Software all Rights Reserved",
License: "GPL"
},
A function object with parameters, where the argument is an object, with attributes
Functionwithparams:function (Paramobj)
{
Use parameters, whether default values are used
var params = paramobj? Paramobj:new function () {
param1= "1";
Param2= "2";
};
return This.Info.Name + ". Functionwithparamobject ";
},
A function object with parameters, where the argument is a variable
Functionwithparam:function (Varparam)
{
Use parameters, whether default values are used
var param = Varparam? Varparam:null;
return This.Info.Name + ". Functionwithparam ";
},
function objects that do not have parameters
Functionwithoutparam:function ()
{
return This.Info.Name + ". Functionwithoutparam ";
}
};
}) (JQuery);
jquery extension function (no need for incoming action object), i.e. API function
;(function ($)
{
$.extend ({
Pif_testextendfunction as an operational object of extended function
In order not to repeat with other plugin names, I use plugin's abbreviated PI_ to define the plugin object prefix
Pif_testextendfunction:
{
The basic information of the extended function
info:{
Name: "Testextendfunction",
Ver: "1.0.0.0",
Corp: "Lzhdim",
Author: "Lzhdim",
Date: "2010-01-01 08:00:00",
Copyright: "Copyright @ 2000-2010 Lzhdim Technology Software all Rights Reserved",
License: "GPL"
},
function object with parameters
Functionwithparams:function (Paramobj)
{
Use parameters, whether default values are used
var params = paramobj? Paramobj: {
param1: "1",
Param2: "2"
};
return This.Info.Name + ". Functionwithparamobect ";
},
A function object with parameters, where the argument is a variable
Functionwithparam:function (Varparam) {
Use parameters, whether default values are used
var param = Varparam? Varparam:null;
return This.Info.Name + ". Functionwithparam ";
},
function objects that do not have parameters
Functionwithoutparam:function ()
{
return This.Info.Name + ". Functionwithoutparam ";
}
}
});
}) (JQuery);
$ (function ()
{
Test Plug-in
var params =
{
PARAM1: "3",
PARAM2: "4"
};
Alert (this). Pi_testplugin.functionwithparams (params));
Alert ($. Pif_testextendfunction.functionwithoutparam ());
});
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.