JQuery namespace and closure usage example, jquery namespace
This document describes the usage of jQuery namespaces and closures. We will share this with you for your reference. The details are as follows:
/** Service company user summary, review */(function () {"use strict"; var companyList = new Object (); // declare the namespace // format the timestamp to the time companyList. getLocalTime = function (nS) {return new Date (parseInt (nS )). toLocaleString (). substr ();} // list of energy-saving service company users var keywords_pagenumber = 1; companyList. getCompanyUser = function () {var url = "/ptsp/rest/company/register/list"; $. get (url, {thisPage: keywords_pagenumber}, function (data) {console. log (data. d Ata. rows); console. log (data. data. pagination); if (data. success) {var result = data. data. rows; var code = ""; for (var I = 0; I <result. length; I ++) {for (var I in result) {var obj = result [I]; var address = obj [5] + obj [6]; var sta = obj [8]; var txt = "" if ("WAIT" = sta) {txt = "awaiting review ";} else if ("YES" = sta) {txt = "reviewed";} else if ("NO" = sta) {txt = "failed ";} code + = "<tr>" + "<td>" + obj [1] + "</td>" + "<td>" + obj [2] + "< /td> "+" <td> "+ addr Ess + "</td>" + "<td> <a href = '/ptsp/web/preview/image? Filename = "+ obj [4] +" 'target = '_ blank'> View </a> </td> "+" <td> "+ txt +" </ td> "+" <td> "+ companyList. getLocalTime (obj [9]) + "</td>" + "<td> <a class = 'btn btn-default btn-sm 'data-toggle = 'modal' href =' # myModalS 'companyid = '"+ obj [0] +" 'onclick = 'companylist. checkCompany (this); '> review </a> </td> "+" </tr> ";}$ (" # companyInfo ").html (code ); // pagination keywords_pagenumber = data. data. pagination. thisPage; var keywords_pagesize = data. Data. pagination. pageRange; var dataSize = data. data. pagination. dataSize; var totalpage = Math. ceil (dataSize/keywords_pagesize); $ ("# exp_keywords_page "). pageBar ({PageIndex: keywords_pagenumber, // current page PageSize: keywords_pagesize, // number of records per page TotalPage: totalpage, // total number of pages RecordCount: dataSize, // total Data Count // isShowPageNumber: false, onPageClick: function (page) {keywords_pagenumber = page; companyList. getCompanyUser () ;}}) ;}$ (Document ). ready (function () {console. log ("check register user"); // list of energy-saving service company users: companyList. getCompanyUser () ;}); // submit $ ('# modalForm1 '). ajaxForm (function (jsonResult) {if (jsonResult. success) {alert ("saved successfully! "); Window. location. reload () ;}else {alert (jsonResult. msg) ;}}) ;}( jQuery );
Note: The namespace of jQuery is similar to the css class, rather than the package in java. The JS closure concept is very simple, that is, the function uses external variables and can be obtained without passing parameters.