3 ms·
Wow, I've been using require.js for more than a year and I've never seen that syntax used. `var module = require('module')` will only work if the module has alr
by STRML 13y ago
Wow, I've been using require.js for more than a year and I've never seen that syntax used. `var module = require('module')` will only work if the module has already been downloaded; otherwise, there's no way it can make an async call and return the result.
What's interesting is that requireJS pulls a move very similar to Angular and reads Function.prototype.toString() to pull those definitions back up into the define() call, so it still works if an async call needs to be made. That's really fantastic. As we've seen with Angular, there are some quirks (old browsers, mainly), but code like this will be optimized out by r.js so there will be no problems in production.
Thanks for the pointer, I may just change all of my definitions after seeing this.