1

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?

Johnny Cheuk
  • 237
  • 2
  • 15
  • @JonathanLonowski So apparently the only problem seems to be I cannot return a value by calling an async function... – Johnny Cheuk Jun 27 '17 at 06:13

0 Answers0