NOTE I now use the conventions detailed in the SUIT framework
Used to provide structural templates.
Pattern
t-template-name
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; |
// Don't actually use this. Ever. Thx. | |
(function fn() { | |
var slice = fn.call.bind([].slice); | |
Function.overload = function(obj) { | |
return function() { | |
var key = slice(arguments).map(function(a) { return typeof a; }).join(', '); | |
if (obj[key]) { |
NOTE I now use the conventions detailed in the SUIT framework
Used to provide structural templates.
Pattern
t-template-name
(function (global) { | |
if ( !global.Event && !('keys' in Object) && !('bind' in Function) ) { return } | |
var eventProto = Event.prototype, | |
EVENTS = { | |
'mouse': [ 'click', 'dblclick', 'contextmenu', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout', 'drag', 'dragend', 'dragenter', 'dragleave', 'dragover', 'drop'], | |
'key': [ 'keydown', 'keypress', 'keyup', 'input'], | |
'res': [ 'load', 'unload', 'beforeunload', 'abort', 'error', 'resize', 'scroll', 'readystatechange' ], | |
'form': [ 'select', 'change', 'submit', 'reset', 'focus', 'blur' ], | |
'ui': [ 'DOMFocusIn', 'DOMFocusOut', 'DOMActivate', 'DOMCharacterDataModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMSubtreeModified' ], |
/* | |
A (very) WIP collection of optimized/recommended jQuery plugin patterns | |
from @addyosmani, @cowboy, @ajpiano and others. | |
Disclaimer: | |
----------------------- | |
Whilst the end-goal of this gist is to provide a list of recommended patterns, this | |
is still very much a work-in-progress. I am not advocating the use of anything here | |
until we've had sufficient time to tweak and weed out what the most useful patterns |
/*This list of snippets doesn't really have any purpose. Just looking through ideas.*/ | |
@mathias: classList based on work by boaz https://gist.github.com/478061 | |
/* | |
Usages: | |
$(selector).classList() // returns an array of classnames | |
$(selector).classList('newclass') // replaces the current element’s classes | |
$(selector).classList(['new', 'class', 'names']) // replaces the current element’s classes | |
*/ |
#!/bin/sh | |
# any2pandoc.sh | |
# | |
# A shell script that tries its best to convert documents thrown at it | |
# to pandoc's extended markdown. | |
# | |
# https://gist.github.com/1181510 | |
# | |
# Depends on: |
#Lessons From A JavaScript Code Review
I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.
##Challenges & Solutions
Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.
Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete
/* | |
* objectClone.js (c) Addy Osmani, 2011. | |
* Do whatever license. | |
* Thanks to gf3 and ben_alman for tips that helped improve. | |
*/ | |
function objectClone(q){ | |
var n = (q instanceof Array) ? [] : {},i; | |
for (i in q) { | |
if (Object.prototype.toString.call({}) == Object.prototype.toString.call( q[i] )) { |
/*! | |
* isVis - v0.5.5 Aug 2011 - Page Visibility API Polyfill | |
* Copyright (c) 2011 Addy Osmani | |
* Dual licensed under the MIT and GPL licenses. | |
*/ | |
(function () { | |
window.visibly = { | |
b: null, | |
q: document, |