Hacker News new | past | comments | ask | show | jobs | submit login

Certainly delete can be useful, but nulling a property has almost the same effect (apart from hasOwnProperty still returning true) - if you're looking at optimising at the level this article is talking about avoiding delete might well be sensible.



This could also be horrible advice, because now you're mixing types which will make your code a little bit more complex, and you'll iterate over this null and have to deal with it. If you have an object property set to null you'll iterate over it, if you delete it you wont. As for the performance improvements, let's see the jsperf.

https://gist.github.com/4018282

Edit: I found a jsperf: http://jsperf.com/delete-vs-undefined-vs-null/6

Delete is a little slower, but setting null can be too, and setting undefined is the fastest for me in stable chrome.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: