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
// A way to use module pattern along with new keyword | |
function Foo() { | |
this.baz = 4; | |
function bar() { | |
return this.baz; | |
} | |
return { | |
"bar":bar.bind(this) | |
}; | |
} |
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
function SomeBuggyInstantiatedObject() { | |
this.name = "bob"; | |
someElement.onclick = function() { | |
alert(this.name); // undefined, because this context is the click event | |
} | |
} | |
function SomeSuperCoolInstantiatedObject() { | |
var that = this; | |
this.name = "bob"; |
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
// document.body.scrollTop = 1; // uncomment this line and it works every time. | |
console.log(daysTop); // 15141 | |
console.log($(document).height()); // 54005 | |
document.body.scrollTop = daysTop; | |
console.log(document.body.scrollTop); // 0, sometimes, in chrome (and the page doesn't move to 15141).... | |
/* | |
if I attach the above code to a click handler, then when the bug occurs, it occurs on | |
every click until I manually scroll the page, then it starts working. |
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
// This is called whenever any data changes that affects the weekly totals | |
// What we do in that case is modify our local representation of the weekly data and emit an event | |
// This way, modules can listen for that event and respond to it without having to wait for | |
// the server to generate new weekly totals |
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
// Hide all miniapps. | |
// for promise().done() explanation, see http://api.jquery.com/promise/#example-1 | |
// tldr; if you put a .complete() callback in an animation which matches > 1 element | |
// the callback will be called once per matching element | |
// We don't want that, we want the callback to run once all animations are complete. | |
$('.miniapp').slideUp("fast").promise().done(function runMeWhenAllSlideupsAreComplete() { |
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
// It would be very simple to write this function to sort-of mimic let; | |
lett({ | |
'blockScopeVar': 4 | |
}, function (blockScopeVar) { | |
//blockScopeVar === 4 // true | |
}); | |
// Then when you want to change the code to actually use let, it's fairly easy; | |
// just write your let declarations and rip out the callback's innards; |
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
$('#calendar .barIcons > .barIcon').each(function (i, icon) { | |
var left; | |
icon = $(icon); | |
left = parseInt(icon.position().left, 10); | |
alert(left); // increases each time | |
return; // Comment this and now the alert is zero each time. | |
icon.css({ | |
"position": "absolute" | |
}); |
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
// Crappy naive debug wrapper function which sucks | |
function debug(msg) { | |
console.log(msg), | |
} |
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
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 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(); | |
} | |
/**/ |
OlderNewer