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
// Crappy naive debug wrapper function which sucks | |
function debug(msg) { | |
console.log(msg), | |
} |
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 debug = true; | |
function parseJSON(json) { | |
debug && console.log('parsing json'); | |
if(typeof json == 'string') { | |
json = JSON.parse(json); | |
} | |
debug && console.log('got json', json); | |
} |
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
// This block is commented out: | |
/** | |
bigBlockOfCode(); | |
lalala(); | |
fooBar(); | |
if(someStuff()) { | |
doExtraThings(); | |
} | |
/**/ |
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
// Define an object using the Revealing Module Pattern | |
var myCounter = function() { | |
// Both Private and Public methods and properties are defined here | |
var counter = 0; | |
function count() { | |
return 0+counter; | |
} |
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 foo = []; | |
setInterval(function() { | |
foo.push(Math.random()); | |
if(foo.length > 200) { | |
foo = foo.slice(-200); | |
} | |
console.log(foo.length); | |
}, 10); |
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
// the following code outputs: 999999999 | |
var someArray = [1,2,3,4,5,6,7,8,9]; | |
for(var i=0 ; i<someArray.length ; i++) { | |
performSomeAsyncOperation("foo", function hereIsACallback() { | |
console.log(someArray[i]); | |
}); | |
} |
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 i=0; | |
// 01234 | |
for(i=0 ; i<5 ; i++) { | |
console.log('standard for loop', i); | |
} | |
// 55555 | |
for(i=0 ; i<5 ; i++) { | |
setTimeout(function() { |
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 handling = false; | |
window.onSomeEvent = function handleEvent() { | |
if(handling) return; | |
handling = true; | |
/* some other handler code here which eventually switches handling off again */ | |
}; |
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 hasMultipleArgs = args.length > 1; | |
var argIsString = typeof arg == 'string'; | |
var argIsSentence = ~arg.indexOf(' '); | |
var argIsFormattingOption = ~arg.indexOf('%'); | |
if (hasMultipleArgs && argIsString && !argIsSentence && !argIsFormattingOption) { /*...*/ } | |
// see https://github.com/observing/devnull/blob/master/lib/logger.js#L364-367 for alternative style |
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
<html> | |
<head> | |
<script> | |
function foo() { | |
alert('bar'); | |
} | |
document.onclick = foo; | |
</script> |
OlderNewer