I want to use object literal notation to generate a namespace:
const featureGoogleAnalytics = {
gTagId: 'G-XXXXXXX', // Your Google Analytics ID
...
resetConsent: () => { // eslint-disable-line no-unused-vars
localStorage.removeItem('googleAnalyticsConsent');
...
return false;
},
/**
* Initializes feature Google Analytics
* Supposed to run after poageload, callback for $( () => { ... } );
*/
init: () => {
this.resetConsent();
...
},
};
Now the line
this.resetConsent();
Errors with
Uncaught TypeError: this.resetConsent is not a function
What did I miss? I assume the syntax of calling the resetConsent
function is wrong, but I wasn’t able to Google it.
2
Answers
The syntax is:
From comments, don’t use an anonymous function wrapper in an Object definition.
Alternatively: