Ensuring that two separate objects have a unique total set of keys

Viewed 39

I have a JS framework and the user can inject values sourced from two different files. The injectable values are identified by the key of the returned object. The problem is that having two separate files means that the keys could clash.

If I have two JS objects like so:

let one = {
  foo: null,
  bar: null
}

let two = {
  foo: null,
  baz: null
}

Is there some way I could ensure the keys are unique across these two objects? I don't think there is a great way to do this, just looking for some possible ideas. Obviously, the two objects above "clash" because they both contain the key "foo".

3 Answers
Related