After going through a lot of project development, I found that more and more methods can be extracted and used as a public method. So how should we implement this idea in js? JS extraction from Public Functions
After going through a lot of project development, I found that more and more methods can be extracted and used as a public method. So how should we implement this idea in js?
Answer
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 the format 12:00:00. 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 ; };
The converted values are as follows:
(Note: Sometimes the file you reference may need to reference other js files. We need to reference the desired js file in the same way)
Implementation
When controller. js references Utils. js, you must write the following statement at the top of controller. js:
Document. write ("