<Script type = "text/javascript"> // create a namespace: jSite. import (namespace) // execute the method process and instance object while creating the namespace // reference: var o = jS. using (namespace, class); or var o = jS. using (namespace); // instance: var o = jS. using ('System. images '); (function (window, undefined) {var document = window.doc ument, navigator = window. navigator, location = window. location; var jSite = (function () {// construct the jSite object var jSite = function (selector, context) {return n Ew jSite. fn. init (selector, context, rootjSite)} jSite. fn = jSite. prototype = {constructor: jSite, init: function (selector, context, rootjSite) {// jSite is a function. The return value of the function is an object and there are many instance methods, these methods are used to operate related nodes}, jsite: "1.1.1", length: 0, size: function () {return this. length ;}}; jSite. fn. init. prototype = jSite. fn; // _______________________________________ factory start __________________________________ jSite. extend = j Site. fn. extend = function () {// static method-factory (the number of merged objects is the target object) var target = arguments [0] | {}, // The first parameter is the target I = 1, length = arguments. length, deep = false, options; if (target. constructor = Boolean) {// The first parameter is bool-type deep = target; // deep copy target = arguments [1] | {}; // target points to the second parameter I = 2;} if (typeof target! = "Object" & typeof target! = "Function") target ={}; // The target is of the string type or ?, If (length = I) {// there is only one parameter? Or deep copy, the two parameters target = this; // The target is this -- I;} for (; I <length; I ++) if (options = arguments [I])! = Null) for (var name in options) {var src = target [name], copy = options [name]; // copy the object if (target = copy) // prevent endless loops. if (deep & copy & typeof copy = "object "&&! Copy. nodeType) // deep copy processing. The deepest element is target [name] = jQuery. extend (deep, src | (copy. length! = Null? []: {}), Copy); else if (copy! = Undefined) // directly copy target [name] = copy;} return target; // return a new target object}; jSite. import = function () {// bind the namespace [Create a namespace] var a = arguments, o = null, I, j, d; for (I = 0; I <. length; I = I + 1) {d = a [I]. split (". "); o = jSite; for (j = (d [0] =" jSite ")? 1: 0; j <d. length; j = j + 1) {o [d [j] = o [d [j] | {}; o = o [d [j] ;}} return o ;}; jSite. using = function (n, o, override) {// combines the namespace with the static method var ns = jSite. import (n), obj ={}; if (typeof (o )! = 'Object' | o = 'undefined') o = ns; ns = function () {}; for (var I in o) {if (o. hasOwnProperty (I )&&(! Obj. hasOwnProperty (I) | override) obj [I] = o [I];} ns. prototype = obj; return new ns;} // ________________________________________ factory end ____________________________________________________ // extend jSite object method jSite. fn. extend ({method: function () {alert ("Implementation of static method extension") ;}}); jSite. extend ({ext: function () {alert ("static method Implementation") ;}}); jSite. system = {Images: {img: 'Implementation of the image method'}, Table: {tbl: 'Implementation of the Table method' }}// return jSite Instance Object return jSite }) (); window. jSite = window. jS = jSite; if (typeof define = "function" & define. amd & define. amd. jSite) {define ("jSite", [], function () {return jSite}) }) (window); var o = jSite. using ('System. images ') alert (o. img); </script>
Download Attachment