Menu item container should be a list
Currently the "items" container in the menu definition is of type Object.
This is risky (at best), as the property order is not guaranteed (see: http://stackoverflow.com/a/5525820/1111580)
Instead, a better type would be a list, e.g. storing the items like so:
selector: '.my-menu',
items: [
{ key: 'item1', name: 'Item 1' },
{ ... },
],
Of course, key I got from the top of my head... probably something more relevant could be chosen.
From same stackoverflow topic:
If you rely on insertion order, you are outside the ECMAScript spec,
but within the de-facto standard of common browser behavior
(AS LONG AS YOUR KEYS DON"T PARSE AS INTEGERS!).
On 09/30/2015 01:46 AM, Tatsujin wrote:
Currently the "items" container in the menu definition is of type |Object|.
This is risky (at best), as the property order is not guaranteed (see: http://stackoverflow.com/a/5525820/1111580)
Instead, a better type would be a list, e.g. storing the items like so:
|selector: '.my-menu', items: [ { key: 'item1', name: 'Item 1' }, { ... }, ], |
Of course, |key| I got from the top of my head... probably something more relevant could be chosen.
— Reply to this email directly or view it on GitHub https://github.com/swisnl/jQuery-contextMenu/issues/283.
As @richpri said, as long as you do not use integers it'll be fine. And if you do, it seems only chrome really resorts. I have seem this same problem in the past in some of our projects.
That may be so, but relying on the fact that most(?) browsers implement it a certain way is risky, at best.
That being said, I think it is mainly unintuitive; the items container is logically a listing (the order is important) not an association (key to information). Associative arrays/hashes/dictionary/map are conceptually non-ordered. I don't quite see what the benefit is from using an object for this?
Also, of course, changing it to list would be a non-breaking change (different container type), but perhaps both would have to be maintained for a while.
I agree with this issue.
In fact I would even go a little further and suggest that the keys be removed. I'm not sure what they provide to the user, and in my current setting, it actually is annoying to provide keys to the items as they are automatically generated.
I would need to dive into the code to see what rammefications that would have. I do understand you feel they should be optional.
Yeah no worries, it's very easy to get around anyway! :)
Current behavior is super annoying when dynamically putting menu items together on server side. Proposed changes should be the new standard.