Skip to content

Instantly share code, notes, and snippets.

@disnet
Created July 30, 2015 20:22
Show Gist options
  • Save disnet/b971aeb690a856b21dd9 to your computer and use it in GitHub Desktop.
Save disnet/b971aeb690a856b21dd9 to your computer and use it in GitHub Desktop.
macro (?.) {
rule infix { $obj:ident | $prop:ident } => {
($obj && $obj.$prop ? $obj.$prop : undefined)
}
rule infix { $obj:expr | $prop:ident } => {
($obj && $obj.$prop ? $obj.$prop : undefined)
}
}
var o = { foo: { bar: 42} };
console.log(o?.foo?.bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment