repl.it
@TobiasParent/

proxiesInJSObjects

Nodejs

FCC Question on "can a property have multiple names?"

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const propertyHandler = {
  get: function(obj, prop){
    const propName = prop.toLowerCase();
    return obj[propName];
  },
  set: function(obj, prop, value){
    const propName = prop.toLowerCase();
    obj[propName] = value;
  }
};

let myObj = new Proxy({}, propertyHandler);

myObj.a = "foo";
console.log(myObj.A);

myObj.aMixedCasePropertyName = 42;
console.log(JSON.stringify(myObj));