what is the point of heterogenous arrays?

后端 未结 8 1197
忘掉有多难
忘掉有多难 2020-12-16 13:43

I know that more-dynamic-than-Java languages, like Python and Ruby, often allow you to place objects of mixed types in arrays, like so:

[\"hello\", 120, [\"w         


        
8条回答
  •  无人及你
    2020-12-16 14:41

    In Lua an object and an array are the same thing so the reason is more clear. Let's say that Lua takes the weak typing to the extreme

    Apart from that, I had a Google Map object and I needed to delete all markers created so far in that map. So I ended up creating an array for markers, an array for circles and an array for places. Then I made a function to iterate over those three arrays and call .remove() on each of them. I then realized that I could just have a single non homogeneous array and insert into them all the objects and iterate once over that array

提交回复
热议问题