Skip to content

Instantly share code, notes, and snippets.

👋
he/him/his

Aaron Gustafson aarongustafson

👋
he/him/his
Block or report user

Report or block aarongustafson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:245831
eCSStender.register(
{'selector': 'p'},
'*',
function( selector, properties, media, specificity )
{
console.log('eCSStender matched the selector "' + selector +
'" in the media type ' + media + '. It’s properties follow:');
console.log(properties);
console.log('The specificity of this selector is ' + specificity);
}
View circular-reference-memory-leak-1.html
<html>
<head>
<title>Circular references between JavaScript and DOM</title>
<script type="text/javascript">
// <![CDATA[
var obj;
window.onload = function()
{
obj = document.getElementById("DivElement");
document.getElementById("DivElement").expandoProperty = obj;
@aarongustafson
aarongustafson / dom-leak-fix.js
Created Dec 5, 2009
Example of a memory leak issue in IE and how to resolve it
View dom-leak-fix.js
window.onload = function()
{
var
body = document.getElementsByTagName('body')[0],
div = document.createElement('div'),
parentDiv, childDiv;
for ( i = 0; i < 5000; i++ )
{
parentDiv = div.cloneNode(true);
parentDiv.onclick = foo;
@aarongustafson
aarongustafson / directly-passed-regexp.js
Created Dec 6, 2009
Regexp performance is faster when you "precompile" (examples from JavaScript Performance Rocks!)
View directly-passed-regexp.js
function directPassing ( string )
{
return string.match( /abc/ );
}
@aarongustafson
aarongustafson / constructors.js
Created Dec 6, 2009
Object and array literals are faster than constructors
View constructors.js
function usingConstructors( string )
{
var a = new Array(), o = new Object();
}
View declare-vars-early.js
function camelize( str )
{
var
HYPHEN = '-',
bits = str.split(HYPHEN),
length = bits.length,
i = 1,
new_str;
if ( length == 1 ) { return bits[0]; }
if ( str.charAt(0) == HYPHEN ) {
View declare-vars-early.js
function camelize( str )
{
var
HYPHEN = '-',
bits = str.split(HYPHEN),
length = bits.length,
i = 1,
new_str;
if ( length == 1 ) { return bits[0]; }
if ( str.charAt(0) == HYPHEN ) {
View execute-if.js
function f( a )
{
if ( a == 1 )
{
// do something
}
}
View tricky-if.js
if ( a++, b == 5 )
{
// always increments a, but ONLY enters the block if b == 5
}
View numeric-variable-pipe.js
function someFunction( n )
{
n |= 1;
// same as n = n || 1;
// doesn't work with anything but numbers
}
You can’t perform that action at this time.