Skip to content

dtao/whatever.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

whatever.js

This library lets you define objects that dynamically define properties as you try to access them (using ES6 Proxies).

Example:

var whatever = require('whatever.js');

var person = whatever();

person.info.name.first = 'Dan';
person.info.address.line1.street = 'Bartlett';
person.employment.company.name = 'Atlassian';

You can also specify defaults for only the properties you care about (e.g., for testing). Accesses to any other properties of the resulting object will just silently do nothing.

var person = whatever({
  info: {
    name: 'Billy'
  }
}));

console.log(person.info.name);   // => 'Billy'