My idea is to call library functions before the library is loaded. So I wrote this:
function moment(date, format)
{
require(['moment'], function (moment) {
// window.moment = moment;
return moment(date, format);
});
}
Everything works fine except when you called:
moment("27/06/2017", "DD/MM/YYYY").format("YYYY-MM-DDTHH:mm:ss");
Since the moment is still undefined, the format function try to calling an undefined object while requireJS is still loading the script asynchronously. How can I handle this situation?