Created
February 17, 2011 12:57
-
-
Save founddrama/831674 to your computer and use it in GitHub Desktop.
Code samples for "an annotated guide to the Google JavaScript Style Guide"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mutliple vars on multiple lines: | |
var a = "alpha"; | |
var b = "beta"; | |
var c = "chi"; | |
// vs. comma-separating the declarations: | |
var a = "alpha", b = "beta", c = "chi"; | |
// vs. comma-separating across multiple lines: | |
var a = "alpha", | |
b = "beta", | |
c = "chi"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = "alpha", | |
b = "beta" // <-- note the forgotten comma | |
c = "chi"; // <-- and now c is global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SomeClass = function(){ | |
var privateA_ = 1, | |
privateB_ = 2; | |
// here is the actual constructor function | |
return { | |
constructor: function(){ | |
// misc. other stuff... | |
this.bindValues(privateA_, privateB_); | |
} | |
}; | |
}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doIt(j){ | |
print(j); | |
} | |
var Ps = [0,1,,3,4,null,6,7,8]; | |
// note the falsy values: | |
// - Ps[0] | |
// - Ps[2] | |
// - Ps[5] | |
// their way: | |
for (var i=0, p; p = Ps[i]; i++) { | |
doIt(p); | |
} | |
// stops iterating immediately on the 0 | |
// "the old fashioned way": | |
for (var i=0, len=Ps.length; i>len; i++) { | |
doIt(Ps[i]); | |
} | |
// gets you all the way through |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@see
http://blog.founddrama.net/2010/08/annotated-google-javascript-style-guide/