Closed EliteMasterEric closed 1 year ago
Good news! This feature has already been accepted and will be coming in a future version of haxe, here’s the accepted proposal
I had searched for "optional chaining" but guess I wasn't thorough enough in my search terms.
Looks like it was already implemented in HaxeFoundation/haxe#10479 and HaxeFoundation/haxe#10561 and appears to be targeting Haxe 4.3.0.
Will close this issue since it's resolved but will leave it here so people searching will find it.
The optional chaining operator (
?.
) would access a property or call a function of an object in a similar manner to.
.However, unlike
.
, if the object whose property is accessed isnull
, or the function being called isnull
,null
will be returned instead of throwing aNull Object Reference
orNull Function Reference
Examples:
Optional chaining operators can be nested:
Optional chaining operators should also be used for function calls:
Optional chaining can also be used to validate function calls:
Specifics
For specifics on niche cases and implementation, refer to how optional chaining is implemented in JavaScript.