ded / script.js

Asyncronous JavaScript loader and dependency manager
MIT License
2.95k stars 341 forks source link

done() function #12

Closed dvv closed 13 years ago

dvv commented 13 years ago

Hi!

Is there a way to get the result of loaded script execution into the callback? Say, $.script('foo', function(foo){ .., live foo here ... }). W/o this feature one has to spoil the global namespace, i presume.

TIA, --Vladimir

ded commented 13 years ago

is this JSONP or regular style AJAX?

dvv commented 13 years ago

Neither. I meant vanilla inclusion of scripts, just as the first example in readme's "Exhaustive list of ways to use $script.js" section.

ded commented 13 years ago

$.script literally just fetches files, it does not return data back in a callback. so i'm guessing you're looking for something like JSONP? Or no?

fat commented 13 years ago

I believe he's talking about something closer to what loadrunner or requirejs does... However this requires you add code to the files you're calling.

dvv commented 13 years ago

Ah. Right you are. There's no means at all, i guess, to catch what's returned from <script src="foo.js"></script>. One has to augment window to get this result.

Still wonder how they cope with that in RequireJS: require([deps], function(return-of-dep0-if-any, return-of-dep2-if-any,...){...})?

dvv commented 13 years ago

@fat: you answered while I was hitting the keyboard :) @ded, @fat: Thanks, closing...

ded commented 13 years ago

if you are indeed looking for some cool exporting requiring libs, i'd urge you to check out one of our favorites (as @fat mentioned) called LoadRunner. It has a nice exporting feature of an async nature.

provide('foo', function (exports) {
  // do shit...
  exports(stuffs);
});

// other file
using('foo', function (stuffs) {
  // do stuff with stuffs...
});