Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* 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