Is Using The Js Delete Operator To Remove A Property From An Object Considered Bad Practice?
When removing a property from an object, I've used the delete operator in the past. But when I had my code reviewed by a person with a CS background, they wanted me to find another
Solution 1:
No, it's not considered bad practice. It just depends on what you want to do,
Read this thread: Garbage Collection and JavaScript "delete": Is this overkill/obfuscation, or a good practice?
Solution 2:
The book "JavaScript, the Good Parts" by Douglas CrockFord says...
The delete operator can be used to remove a property from an object. It will remove a property from the object if it has one. It will not touch any of the objects in the proto- type linkage.
I think you can use the Delete
operator without worries. There are many other ways to remove a property from an object, but all they are more expensive in my opinion.
Post a Comment for "Is Using The Js Delete Operator To Remove A Property From An Object Considered Bad Practice?"