JavaScript Delete Keyword Troubles

JavaScript 0 No Comments

I have always thought the delete keyword in JavaScript had limited value, because it never behaved quite like I expected it to. Here’s a detailed discussion on why that is. I wasn’t aware of all the odd behaviors you can experience depending on the context and the browser you’re using. Also a great primer on JavaScript code contexts — one of the less talked about aspects of JavaScript that I think tends to throw the newbies for a spin now and then. Discusses in more detail the mechanics of how “variable hoisting” and “function hoisting” work:

Read Understanding Delete on

.filter() to the rescue

As an alternative to delete, for some use cases, you may want to consider using the Array .filter method. Or, perhaps better, the Underscore library’s .select() method, which works equally well on objects, and delegates to the native .filter() if it exists.

Underscore.js is a utility function library that brings a lot of functional programming methods (some of which are included in the new JavaScript specification) into current and old browsers. It’s not a direct 1:1 shim, and it does not modify native object prototypes. It’s more like jQuery — definitely introducing third party library code and syntax to your projects. In my opinion, it’s worth it. Check it out.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">