if I change the code to whethaer second option. It will be problematic, and if so, why ???
I do not recommend making this change because it can be problematic, generally speaking. The documentation for require.nextTick (which appears immediately before the function definition) says:
Run something after the current tick of the event loop.
Calling fn synchronously violates the specification that execution should be performed "after the current tick." (See the end of my answer for a possible objection here.)
If you're wondering why this might be a problem, consider RequireJS listening for DOM events. One thing that has a function like require.nextTick is that it allows event handlers to fire . If you set require.nextTick to execute your function synchronously, you do not allow event handlers to fire. In some cases, this may cause RequireJS to stop working properly.
At this point, one could argue that the definition of nextTick is such that it can invoke its fn synchronously, because if setTimeout not defined, it invokes fn synchronously:
req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) { setTimeout(fn, 4); } : function (fn) { fn(); };
I think this is intended for unusual cases , and not for the queue at the mill, where the modules are loaded via HTTP requests asynchronously. In some cases, such as embedded devices that lack the JS environment provided by browsers or Node.js, the only way to run a piece of software using RequireJS is to download the optimized package that passed through r.js and enable require.js in the kit. In a case like this , calling nextTick call fn will be controversial at the same time, because by the time RequireJS is executed, all modules are already loaded.
Louis source share