Can someone please help me understand the scoop of JavaScript variables, and how to reach them?
Imagine the following...
// Namespace declaration
var p = {};
p.result = {
searchForm: $('#search-form'),
searchAction: this.searchForm.attr('action'),
anotherSection: {
hello: 'Hello ',
world: this.hello + 'world!'
}
}
This won't work, and it gives the error saying this.searchForm
is undefined. The same error appears in anotherSection
as well (ofc).
How can I declare a variable in terms of another variable inside the same namespace?