Skip to content

Instantly share code, notes, and snippets.

@maxbeatty
Created July 2, 2014 16:50
Show Gist options
  • Save maxbeatty/c0521cf3d311dfb9eabc to your computer and use it in GitHub Desktop.
Save maxbeatty/c0521cf3d311dfb9eabc to your computer and use it in GitHub Desktop.
CoffeeScript checking if key exist in object

You would think it works just like JavaScript:

'pushState' in window.history

But this actually compiles to:

var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
__indexOf.call(window.history, 'pushState') >= 0;

What you want to do is use of instead of in:

'pushState' of window.history

which compiles as intended:

'pushState' in window.history;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment