Skip to content

Instantly share code, notes, and snippets.

@subimage
Created June 28, 2012 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subimage/3013824 to your computer and use it in GitHub Desktop.
Save subimage/3013824 to your computer and use it in GitHub Desktop.
How you can totally fuck yourself with JavaScript in IE.
// Inline assignment inside an 'if' statement works with most programming languages.
// However, in JavaScript there's a gotcha.
// This works in Safari, Firefox & Chrome...but will destroy your life in IE.
if(thing=functionThatReturnsThing()) {
doStuff();
}
// Do this instead
var thing=functionThatReturnsThing();
if(thing) doStuff();
@subimage
Copy link
Author

Adding on...it seems this pops up reliably in IE when using the .each function of prototype or jquery

    item_cids.each(function(cid, i){
      var item = _App.models.items.getByCid(cid);
      if(item) {
        item.set({rank: i}, {silent: true});
      }
    });

IE will complain about 'set' not being available if you try to assign item inline with the if statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment