Ad
Duplicate Key In Javascript Object
I've been working on voxeet-react-components
and found something funny.
Some objects in the source code has duplicated keys. For example:
import LocalizedStrings from 'react-localization';
export const strings = new LocalizedStrings({
en: {
// ...rest omitted
presenter: "Attendees", // line 75
joined: "Joined",
invited: "Waiting on",
presenter: "Presenter", // line 79
// ... rest omitted
},
// ... rest omitted
});
How does react-localization work for duplicated keys? And that is not all.
// ...rest omitted
module.exports = {
reducer,
StatusButton,
ReplayButton,
StatusCard,
ConferenceRoom,
Buttons:{
ToggleMicrophoneButton,
ToggleModeButton, // line 32
ToggleRecordingButton,
ToggleScreenShareButton,
ToggleSettingsButton,
ToggleVideoButton,
HangupButton,
ToggleFullScreenButton,
ToggleModeButton, // line 39
HangUpButtonBottomBar,
Toggle3DAudioButton,
ToggleExternalLiveButton,
ToggleAttendeesChatButton,
TogglePSTN,
ToggleAttendeesListButton
}
}
Is it just some kind of mistake? Otherwise, how does react work for duplicated components?
Ad
Answer
The object doesn't have duplicate keys, the object literal in the source code does.
This is an error (or at least nonsense) on the part of the author. Only the last value will be assigned for the given property.
const foo = {
a: 1,
b: 2,
b: 3,
c: 4
};
console.log(foo);
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad