$.extend({
minValue:function(a,b){
return a<b?a:b;
}
})
$.minValue(5.6);
$(document).ready(function(){
$.fn.extend({
theAlert:function(){
alert(“自定义的函数”);
}
})
$(“thediv”).theAlert()
})
2 javascript的方法可以分为三类:
a 类方法
b 对象方法
c 原型方法
例子:
复制代码
function People(name)
{
this.name=name;
//对象方法
this.Introduce=function(){
alert("My name is "+this.name);
}
}
//类方法
People.Run=function(){
alert(“I can run”);
}
//原型方法
People.prototype.IntroduceChinese=function(){
alert(“我的名字是”+this.name);
}
//测试
var p1=new People(“Windking”);
p1.Introduce();
People.Run();
p1.IntroduceChinese();
function baseClass()
{
this.showMsg = function()
{
alert(“baseClass::showMsg”);
}
}
function extendClass()
{
}
extendClass.prototype = new baseClass();
var instance = new extendClass();
instance.showMsg(); // 显示baseClass::showMsg