- Part 1 - Style Guide
- Chapter 1 - Basic Formatting
- Chapter 2 - Comments
- Chapter 3 - Statements
- Chapter 4 - Functions and Expressions
- Part 2 - Programming Practices
- Chapter 5 - Loose Coupling
- Chapter 6 - Avoid Globals
- Chapter 7 - Event Handling
- Chapter 8 - Avoid Null Comparisons
This file contains 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
<!-- autofocus shim for older browsers that doesn't impact newer ones --> | |
<input type="text" name="q" id="q" autofocus> | |
<script> | |
(function(textbox){ | |
if (textbox.autofocus !== true){ | |
textbox.focus(); | |
} | |
})(document.getElementById("q")); | |
</script> |
This file contains 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
/* | |
* Another ES6 Proxy experiment. This one creates a stack whose underlying | |
* implementation is an array. The proxy is used to filter out everything | |
* but "push", "pop", and "length" from the interface, making it a pure | |
* stack where you can't manipulate the contents. | |
*/ | |
var Stack = (function(){ | |
var stack = [], |
This file contains 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
info it worked if it ends with ok | |
verbose cli [ 'node', '/usr/local/bin/npm', 'update', 'npm', '-g' ] | |
info using npm@1.0.10 | |
info using node@v0.4.10 | |
verbose config file /home/nicholas/.npmrc | |
verbose config file /usr/local/etc/npmrc | |
silly exec /usr/local/bin/node "/usr/local/lib/node_modules/npm/bin/npm-get-uid-gid.js" "nobody" 1000 | |
silly output from getuid/gid {"uid":65534,"gid":1000} | |
silly output from getuid/gid | |
silly testEngine { name: 'csslint', |
This file contains 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
//BSD Licensed | |
var YourGlobal = { | |
namespace: function(ns){ | |
var parts = ns.split("."), | |
object = this, | |
i, len; | |
for (i=0, len=parts.length; i < len; i++) { | |
if (!object[parts[i]]) { |
This file contains 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
<target name="compress"> | |
<!-- store filenames in a property delimited by ; --> | |
<pathconvert pathsep=";" property="compress.jsfiles"> | |
<fileset dir="${build.dir}" includes="*.js"/> | |
</pathconvert> | |
<script language="javascript"><![CDATA[ | |
importPackage(java.io); |
JSLint doesn't like using new function
. This makes sense, because you're just creating a singleton, and so there's no point in using a constructor for that. If you have something like this:
var NowWithClosures = Backbone.Model.extend(new function(){
var x = 1;
this.initialize = function(){
console.log('init');
};
this.AddOneToX = function(){
x++;
This file contains 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
#!/usr/bin/env node | |
var child = require('child_process'); | |
var cp = child.spawn("dir", [""]); | |
cp.stdout.on("data", function(data) { | |
console.log(data.toString()); | |
}); | |
cp.stderr.on("data", function(data) { | |
console.error(data.toString()); |
This file contains 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
/* | |
* Contest to win one of my books. If you're in the United States, you can choose either | |
* Professional JavaScript for Web Developers or Maintainable JavaScript and I will send | |
* you a signed copy. If you're outside the United States, I will send you the PDF version | |
* of either book. Good luck! | |
* | |
* Rules | |
* 1. Assume this is the only code! Don't worry about real world situations. | |
* 2. You can use anything defined in ECMAScript 5 to solve the problem (no DOM, BOM, etc.) | |
* 3. There is more than one correct answer but only the first correct answer wins. |