I've been working on upgrading some code to use ES6 syntax. I had the following line of code:
delete this._foo;
and my linter raised a suggestion to use:
Reflect.deleteProperty(this, '_foo');
You can find the documentation for this method here.
The MDN docs state:
The Reflect.deleteProperty method allows you to delete a property on an object. It returns a Boolean indicating whether or not the property was successfully deleted. It is almost identical to the non-strict delete operator.
I understand that the delete
keyword does not return a value indicating success, but it is much less verbose.
If I'm not dependent on the success/failure of delete
is there any reason to favor Reflect.deleteProperty
? What does it mean that delete
is non-strict?
I feel like a lot of the use cases for the Reflect
API are for resolving exceptional cases and/or providing better conditional flow, but at the cost of a much more verbose statement. I'm wondering if there's any benefit to use the Reflect
API if I'm not experiencing any issues with my current usages.