Last active
March 19, 2020 14:14
-
-
Save bendtherules/3467664a9c567617342b73c3681c1dc7 to your computer and use it in GitHub Desktop.
IsPropertyReference? - Example for foo.bar() article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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