Skip to content

Instantly share code, notes, and snippets.

@vincentchu
Created April 30, 2010 17:57
Show Gist options
  • Save vincentchu/385552 to your computer and use it in GitHub Desktop.
Save vincentchu/385552 to your computer and use it in GitHub Desktop.
// Google Closure Compiler examples
// Malformed JS
var foo = {
attrib1: 'foo',
attrib2: 'bar', // <--- trailing comma
}
// RESULT:
// [vincentc@local bad_js]$ gjs --js bad_js.js
// bad_js.js:8: ERROR - Parse error. Internet Explorer has a non-standard intepretation of trailing commas. Arrays will have the wrong length and objects will not parse at all.
// }
//
// 1 error(s), 0 warning(s)
// Really wordy JS
var bar = function () {
// I am a really wordy js file
// with many cool comments!
console.log("I am a debug statement");
x = 10;
if (true) {
x = 1 + 1;
new Ajax.Updater('', {
// We like to make tons of comments
onSuccess: function () {
$('cool_div').hide();
},
onComplete: function () {
$('cool_div').show();
}
});
}
}
// RESULT (notice: the if block has been removed since it always evals to true.
// The '1+1' evaluation has just been replaced by 2):
// [vincentc@local bad_js]$ gjs --js bad_js.js
// var bar=function(){console.log("I am a debug statement");x=10;x=2;new Ajax.Updater("",{onSuccess:function(){$("cool_div").hide()},onComplete:function(){$("cool_div").show()}})};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment