代码之家  ›  专栏  ›  技术社区  ›  Cofey

需要点符号帮助

  •  1
  • Cofey  · 技术社区  · 14 年前

    下面是我的对象的一个示例:

    var fruit = {
        apple: {
        }
    }
    
    var apple = this.rel;
    

    有人能告诉我为什么这样做吗:

    fruit[apple]
    

    这不是吗?

    fruit.apple
    
    1 回复  |  直到 14 年前
        1
  •  5
  •   kennytm    14 年前

    在Javascript中 foo.bar 相当于 foo["bar"] ,不是 foo[bar] .

    因此, fruit.type 会变成 fruit["type"] ,但没有 type: 领域 fruit 反对,所以 水果.类型 返回未定义。