1

为什么在“creditText”行上说“lbp is undefined”?如何在这样的配置文件中引用以前的属性?

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
    }
}

在此先感谢您的帮助

4

3 回答 3

3

你没有。在对象被关闭之前, lbp 不会存在于当前作用域的符号表中。

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
};
于 2010-04-26T22:05:28.410 回答
0

你不能,你的 lbp 变量没有定义,因为声明的最后一个括号是关闭的。

于 2010-04-26T22:06:35.643 回答
0

我猜想在将值分配给 lbp 变量之前,正在解释您正在定义的对象的内容。如果不在单独的指令中分配值,我认为没有任何方法可以做你想做的事。

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 };
于 2010-04-26T22:14:00.867 回答