Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Last active December 30, 2018 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglascayers/99f891420e0726c1e835c30ad56bb65d to your computer and use it in GitHub Desktop.
Save douglascayers/99f891420e0726c1e835c30ad56bb65d to your computer and use it in GitHub Desktop.
/* SharedLibrary.js, upload as a static resource */
window.sum = function(a, b) {
return ( a + b );
}
<!-- YourComponent.cmp -->
<aura:component>
<ltng:require scripts="{!$Resource.SharedLibrary}"
afterScriptsLoaded="{!c.getSum}"/>
</aura:component>
/* YourComponentController.js */
({
getSum: function(component, event, helper) {
let sum = window.sum(2, 3); // use shared function on `window` object
console.log(sum); // 5
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment