snootforge

chee/object-with-default-value

an object with a default value, using Proxy

object with default value

  1. const objectDefault = require('object-with-default-value')
  2. const lol = objectDefault({a: 1, b: 2, c: 3}, 100)
  3. console.log(lol.a) // 1
  4. console.log(lol.b) // 2
  5. console.log(lol.wow) // 100

you can still set things like normal:

  1. console.log(lol.dog) // 100
  2. lol.dog = 'henry'
  3. console.log(lol.dog) // "henry"