Help me figure it out. 1 line - an object is created, and the rest create associative arrays and methods are written in them?

var handle = {} handle["/"] = requestHandlers.start; handle["/start"] = requestHandlers.start; handle["/upload"] = requestHandlers.upload; 

    1 answer 1

    There are no associative arrays in JavaScript. If you need to store multiple key: value pairs, use objects. Objects cannot be considered associative arrays, since they do not keep order.

    In the code above, an empty object is created, and the values ​​are written in the fields with the corresponding key.

    • 3
      @Asen - yeah, right ... $ array = array (); This is also a namespace: D - Zowie
    • 2
      Creating an instance of the Object class as if not? Oh lol, read carefully - Preparation ** of the object ** (namely the object) support namespace. For those who are particularly aware, there are no namespaces in JS and objects are used to simulate them. PS: also argues, OMG - Zowie
    • 2
      > used for namespace emulation This is not a namespace. Just like that, you can structure the code in javascript, that's all. - Vladimir Gordeev
    • 2
      So you can emulate a namespace, in fact, it's about the same namespace as a static class. If it is written there to define a new namespace , i.e. word for word, then in a bucket book because it is absurd. var handle={} == var handle=new Object() what did you want to say with this? .. PS: you should not prove what you are not sure about or you do not understand. It is better to write something like this - I think, I suppose, etc. PPS: Neither the book nor the link you provide is an authoritative source. By the same, under the link, everything is correctly written, you just were inattentive - Zowie
    • one
      In my opinion with different words about the same thing. var handle = {} - indeed, it can be interpreted as creating a new namespace. Although of course, an object is created here. - ivkremer