Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created April 16, 2010 13:04
Show Gist options
  • Save phiggins42/368380 to your computer and use it in GitHub Desktop.
Save phiggins42/368380 to your computer and use it in GitHub Desktop.
(function(bug){
buggyfunction = function(msg){
// summary: Alert some message.
// msg: String|Object
// If string, just show this message. If object,
// use obj.message for display, and hide
// obj.delay ms
var delay;
if(typeof msg == "string"){
msg = msg;
}else{
msg = msg.message;
delay = msg.delay || 0;
}
delay && setTimeout(hidedialog, delay);
showdialog(msg);
};
buggyfunction("Test"); // alerts now.
buggyfunction({ message:"Test", delay:4000 }); // alerts now. should wait 4s
})();
// ignore the fact we _could_ just !== "string" and do the object stuff. There's
// other logic in that inital if() and other goodness that needs to happen,
// which is why it worked out in the flow it did. The bug is glaringly obvious
// and largely unrelated to that msg = msg; line that otherwise seems
// unnecessary.
//
// i hate myself after spotting why no matter what I pass a { delay:..} ends
// up being 0. Thank you, debugger; I'm an idiot.
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment