I have a variable set to an object:
var myConfig = {
elementID: "Test",
cookieName: "myTest",
cookieExpiresAfterDays: 1,
cookieDomain: ".localhost:3000/",
privacyPolicy: "",
services: [
{
name: "GoogleAnalytics",
default: !0,
required: !0,
onlyOnce: !0,
},
],
translations: {
GoogleAnalytics: {
description: `<p>CookieDomain: ${cookieDomain}</p>`,
title: "Google Analytics",
},
}
};
In this block:
translations: {
GoogleAnalytics: {
description: `<p>CookieDomain: ${cookieDomain}</p>`,
title: "Google Analytics",
},
}
I need to set cookieDomain: cookieDomain but it returns me an error
Uncaught ReferenceError: cookieDomain is not defined
and when I try cookieDomain: this.cookieDomain it prints undefined.
How can I access the correct value?
Advertisement
Answer
you have two solutions here either
define the
cookieDomainvariable in the same file before the initializingmyConfigobjectpass the
cookieDomainvalue as a parameter so themyConfigobject would be
var myConfig = {
elementID: "Test",
cookieName: "myTest",
cookieExpiresAfterDays: 1,
cookieDomain: ".localhost:3000/",
privacyPolicy: "",
services: [
{
name: "GoogleAnalytics",
default: !0,
required: !0,
onlyOnce: !0,
},
],
translations: ({cookieDomain}) => {
GoogleAnalytics: {
description: `<p>CookieDomain: ${cookieDomain}</p>`,
title: "Google Analytics",
},
}
};
and then you need to call the translations block by
myConfig.translations({cookieDomain: 'some value here'});