Skip to content

Instantly share code, notes, and snippets.

@iaincarsberg
Created March 15, 2012 11:51
Show Gist options
  • Save iaincarsberg/2043844 to your computer and use it in GitHub Desktop.
Save iaincarsberg/2043844 to your computer and use it in GitHub Desktop.
Using Use.js to expose global functions form a non-amd script
function helloWorld () {
return "Hello, World!";
}
function lorem () {
return "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
}
require.config({
"use": {
"hasglobals": {
"attach": function () {
return {
helloWorld: window.helloWorld,
lorem: window.lorem
};
}
}
}
});
require(
[
'use!hasglobals'
],
function (hasglobals) {
console.log(hasglobals.helloWorld());// Hello World!
console.log(hasglobals.lorem());// Lorem ipsum dolor sit a...
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment