<script>
JS extension string function test, other analogy
String.prototype.test = function (s) {
alert (this+s);
}
var str = ' Hello ';
Str.test (' World ');//helloworld
JQ extension
(function ($) {
$.fn.test = function (OP) {
var defaults = {A: ' No '}
var setings = $.extend (DEFAULTS,OP);
alert (SETINGS.A);
}
}) (JQuery);
Call
$ (function () {
$ (). Test ();
$ (). Test ({A: ' yes '});
})
</script>
JS extension Method: 1 Define class static method extension 2 Define Class object method extension
var aclass = function () {}
1 defining static methods for this class
Aclass.sayhello = function () {
Alert (' Say hello ');
}
2 Defining object methods for this class object
AClass.prototype.protoSayHello = function () {
Alert (' prototype say hello ');
}
Aclass.sayhello (); static method of//aclass
var aobject = new AClass ();
Aobject.protosayhello (); Method extensions for Class objects
Method Extensions for jquery
Defining extension methods for jquery
1 static methods for defining jquery
Jquery.extend ({
Statichello:function () {
Alert ("WWG, Statichello");
}
});
var str = $.statichello ();
2 Defining extension methods for jquery objects
JQuery.fn.ObjHello = function () {
Return alert ("Objhello");
}
$ ("#htmlDiv"). Objhello ();