I have following JS file uploaded as static resource in Salesforce.
Static resource utility.zip / utility.js file
var x = function (a, b) {return a * b};
I would like to call function variable from static resource JS file from LWC component.
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import utility from '@salesforce/resourceUrl/utility';
export default class lwccomponent extends LightningElement {
renderedCallback() {
Promise.all([
loadScript(this, utilities + '/utility.js')
])
.then(() => {
alert('loaded');
/* how can i call method / function variable from JS file , i am unable to do it. */
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading JS file',
message: error.message,
variant: 'error'
})
);
});
}
}
my objective is to create a common set of functions to share among components/ project to have to prevent any data issues.