about 5 months ago - 1 comment
I got this from Underscore.js. ###* Calling a debounced function will postpone its execution until after wait milliseconds have elapsed since the last time the function was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. For example: rendering a preview of a Markdown comment, recalculating a layout after…
about 8 months ago - 4 comments
Pasting anything other than simple text into the browser has historically been stupendously impossible. Until now… It’s a miracle, image data pasted into the browser can be retrieved with JavaScript (at least since Chrome 13.0.782.220)! Just use this jQuery plugin and start receiving paste events with images all their sweet gooey image data. This picks…
about 9 months ago - No comments
Hey! I know that you want to use joysticks and gamepads in your HTML/JavaScript games, so what are you waiting for? Check out Boomstick and give it a shot. This cross-platform, multi-browser extension gives JavaScript access to all joysticks on all platforms. Pretty rad. Right now I’m having great results with it in my game…
about 10 months ago - No comments
I was looking into how paper.js did their operator overloading and what I found was pretty clever: var operators = { ‘+’: ‘add’, ‘-’: ‘subtract’, ‘*’: ‘multiply’, ‘/’: ‘divide’, ‘%’: ‘modulo’, ‘==’: ‘equals’, ‘!=’: ‘equals’ }; function $eval(left, operator, right) { var handler = operators[operator]; if (left && left[handler]) { var res = left[handler](right);…
about 1 year ago - 1 comment
There’s been quite a bit of copy/pasting of the compatibility shim for requestAnimationFrame going around on the Net, which is all fine and dandy, but sadly the popular shim isn’t compatible with passing in the timestamp on the setTimeout fallback. Here’s the improved one: window.requestAnimationFrame ||= window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || (callback,…
about 1 year ago - No comments
This comes up all the time, you have an element, and you want to select it to be the sole active element from among it’s siblings. With jQuery that is simple enough: element.addClass("active").siblings().removeClass("active") Though it is not as simple as it can be and it also fails to chain well. The solution is a super…
about 1 year ago - No comments
Recently I was running into a problem with JSDock Toolkit where it would throw an error saying js: exception from uncaught JavaScript throw: java.lang.OutOfMemoryError: Java heap space. The solution was to add the -s flag so that it would not try and generate a large, marked-up source file for viewing with the docs. java -jar…
about 1 year ago - No comments
Here’s some recent videos demoing the magically rapid prototyping of Pixie.
about 1 year ago - No comments
/** * Pretend the array is a circle and grab a new array containing length elements. * If length is not given return the element at start, again assuming the array * is a circle. * * @param {Number} start The index to start wrapping at, or the index of the * sole element to…
about 1 year ago - No comments
Here’s a useful little method that empties out an array. Sure you could type myArray.length = 0; but that is kind of weird. For some reason myArray.clear() just makes more sense to me. /** * Empties the array of it’s contents. It is modified in place. * * @type Array * @returns this, now emptied.…