How would I go about referencing a JavaScript hash key within the object itself? Fore example, I want to be able to actually make use of the "theme" key. Would I use "this" to reference "theme"?
window.EXAMPLE = {
config : {
theme: 'example',
image_path: '/wp-content/themes/' + this.theme + '/img/',
}
}
You could use a method:
window.EXAMPLE = {
config : {
theme: 'example',
image_path: function () {
return '/wp-content/themes/' + this.theme + '/img/';
},
}
}
Of course, then you have to access it via EXAMPLE.config.image_path()
You should probably not be defining things on window
either, and just use whatever the current scope is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With