Skip to content

Instantly share code, notes, and snippets.

@xl1
Last active August 29, 2015 14:02
Show Gist options
  • Save xl1/e1f1876fad1aec669b0d to your computer and use it in GitHub Desktop.
Save xl1/e1f1876fad1aec669b0d to your computer and use it in GitHub Desktop.
require 'harmony-reflect'
LazilyExtensible = (obj) ->
switch typeof obj
when 'object', 'function'
Proxy obj,
get: (target, name) ->
if target[name] is undefined
target[name] = LazilyExtensible {}
else
target[name]
else
obj
obj = LazilyExtensible { a: 1 }
console.log obj.a # => 1
obj.b.c = 2
console.log obj.b.c # => 2
obj[123][456][789] = (value) -> @abc.def.ghi = value
obj[123][456][789] 'foobar'
console.log obj[123][456].abc.def.ghi # => "foobar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment