repl.it
@ulisesantana/

JS Proxy

Nodejs

No description

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
19
const envVar = Math.random() > 0.5 ? 'ANDROID' : 'IOS'
const handler = {
    get: function(target, name){
      return name in target ?
        target[name] :
        'v3';
    }
  };

const versions = {
  user: new Proxy({ANDROID:'v5', IOS:'v2'}, handler),
  balance: new Proxy({ANDROID:'v2', IOS:'v2'}, handler)
};

console.log('User mobile version: ', envVar, versions.user[envVar]);
console.log('User web version: ', versions.user['meh']);
console.log('Balance mobile version: ', envVar, versions.balance[envVar]);
console.log('Balance web version: ', versions.balance['whatever']);
Fetching token
?