Skip to content

Instantly share code, notes, and snippets.

@bendtherules
Last active March 19, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendtherules/3467664a9c567617342b73c3681c1dc7 to your computer and use it in GitHub Desktop.
Save bendtherules/3467664a9c567617342b73c3681c1dc7 to your computer and use it in GitHub Desktop.
IsPropertyReference? - Example for foo.bar() article
// IsPropertyReference?
// 1. Different notations for accessing a property name
foo.bar() // ✅
foo["any string here"]() // ✅
// 2 Property name can also be a symbol - inbuilt or custom
someArray[Symbol.iterator].toString() // ✅
foo[Symbol("bar")]() // ✅
// 3. Chained is ok (this = last chained obj)
foo.foo1.bar() // (this = foo.foo1) ✅
foo.foo1.["any string here"]() // ✅
// 4. LHS can also be a primitive
"hello world".toUpperCase() // ✅
true.toString(); // ✅
// 5. LHS can be be wrapped in parenthesis
(foo.bar)() // ✅
(foo["bar"])() // ✅
// 6. LHS can not be a complex expression or a function variable
someFn = foo.bar;
someFn() // ❌
(hello = foo.bar)() // ❌
(0, foo.bar)() // ❌
// 8. Object part of the LHS can be a complex expression
(foo1 = foo).bar() // ✅
createFoo().bar() // ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment