Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.