You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For JSONP, you might want to consider accepting a function as argument so that your script can define the function for the user. Besides this allowing for inline functions (or functions supplied as a variable name as opposed to string), your script could, if a callback name is not also supplied, set an auto-incrementing name for the function and append this name to the URL for the user (e.g., &callback=simpleLoadScript.jsonp123) assuming the server is configured to add dynamic callback names. Note that it can also be convenient to namespace the callbacks (on simpleLoadScript itself in this example), so new globals are not introduced, even temporarily.
In combination, this can avoid globals while allowing unnamed inline functions to be provided on the fly (and also de-uglify the supplied URL in avoiding manually setting its callback argument).
This would make Promise.all more convenient, as it could allow JSONP to be retrieved concurrently with the results handled in one callback. The other disadvantage besides breaking compatibility is that you have to flag, e.g., with an argument as I did above, that this is JSONP.
Incidentally, I think you can avoid your all method by accepting an array for the url argument.
Hi!
A nice simple but robust tool!
For JSONP, you might want to consider accepting a function as argument so that your script can define the function for the user. Besides this allowing for inline functions (or functions supplied as a variable name as opposed to string), your script could, if a callback name is not also supplied, set an auto-incrementing name for the function and append this name to the URL for the user (e.g.,
&callback=simpleLoadScript.jsonp123
) assuming the server is configured to add dynamic callback names. Note that it can also be convenient to namespace the callbacks (onsimpleLoadScript
itself in this example), so new globals are not introduced, even temporarily.In combination, this can avoid globals while allowing unnamed inline functions to be provided on the fly (and also de-uglify the supplied URL in avoiding manually setting its callback argument).
We use this approach at https://github.com/brettz9/jp/blob/master/index.js for our JSONP-only tool.
Alternatively, and in some ways I think even cooler though breaking prior compatibility, you could accept an API like this:
This would make
Promise.all
more convenient, as it could allow JSONP to be retrieved concurrently with the results handled in one callback. The other disadvantage besides breaking compatibility is that you have to flag, e.g., with an argument as I did above, that this is JSONP.Incidentally, I think you can avoid your
all
method by accepting an array for the url argument.In combination, one could do this:
or if in an environment supporting
await
:The text was updated successfully, but these errors were encountered: