Autovivification and Javascript

前端 未结 2 1887
你的背包
你的背包 2020-12-11 04:46

Does autovivification only have to do with \"derefencing\" undefined structures, because in JavaScript if you specify a index or a property that doesn\'t exist won\'t it dyn

2条回答
  •  没有蜡笔的小新
    2020-12-11 04:55

    Namespacing is one area where autovivification might be handy in JavaScript. Currently to "namespace" an object, you have to do this:

    var foo = { bar: { baz: {} } };
    foo.bar.baz.myValue = 1;
    

    Were autovivification supported by JavaScript, the first line would not be necessary. The ability to add arbitrary properties to objects in JavaScript is due to its being a dynamic language, but is not quite autovivification.

提交回复
热议问题