views:

33

answers:

3

Why is it saying that "lbp is undefined" on the line of "creditText"? How do I refer to previous properties in a config file such as this?

var lbp = {

    // Pertinant page properties, such as Author, Keywords, URL or Title
    page: {
        theURL: window.location.toString(),
    },

    // Configurable user defaults
    defaults: {
        creditText: lbp.page.theURL
    }
}

Thanks in advance for your help

+3  A: 

You don't. lbp won't exist in the current scope's symbol table until the object is closed out.

var lbp = {
    // Pertinant page properties, such as Author, Keywords, URL or Title
    page: {
        theURL: window.location.toString(),
    }      
}; // NOW you can reference lbp by name

lbp.defaults = {
  creditText: lbp.page.theURL
};
Peter Bailey
A: 

You just can't, your lbp variable is not defined since the last parenthesis of the declaration is closed.

systempuntoout
A: 

I would guess that the contents of the object you are defining are being interpreted before the value is assigned to the lbp variable. I don't think there's any way to do what you want without assigning the values in a separate instruction.

var lbp = {};
// Pertinant page properties, such as Author, Keywords, URL or Title
lbp.page = { theURL: window.location.toString() };
// Configurable user defaults
lbp.defaults = { creditText: lbp.page.theURL };