After experiencing a "large number" of project development, I found that more and more methods can be extracted and used as a public method. So, how to implement this idea in js?
For example, the following method is used to convert the standard time Thu Mar 19 2015 12:00:00 GMT+0800 (China Standard Time) to 2015-03-19 12:00:00 format. ShopStatementController
##
var formatDateTime = function (date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); var minute = date.getMinutes(); minute = minute < 10 ? ('0' + minute) : minute; var second = date.getSeconds(); return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second ; };
document.write("<script language=javascript src='js/import.js'></script>");
"");
Write the above method body in Utils.js. The above is the content of JavaScript Advanced (1) Extracting Public Functions. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!