Skip to content

Instantly share code, notes, and snippets.

View aarongustafson's full-sized avatar
👋
he/him/his

Aaron Gustafson aarongustafson

👋
he/him/his
View GitHub Profile
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);
}
<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 December 5, 2009 19:37
Example of a memory leak issue in IE and how to resolve it
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 December 6, 2009 00:40
Regexp performance is faster when you "precompile" (examples from JavaScript Performance Rocks!)
function directPassing ( string )
{
return string.match( /abc/ );
}
@aarongustafson
aarongustafson / constructors.js
Created December 6, 2009 00:44
Object and array literals are faster than constructors
function usingConstructors( string )
{
var a = new Array(), o = new Object();
}
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 ) {
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 ) {
function f( a )
{
if ( a == 1 )
{
// do something
}
}
if ( a++, b == 5 )
{
// always increments a, but ONLY enters the block if b == 5
}
function someFunction( n )
{
n |= 1;
// same as n = n || 1;
// doesn't work with anything but numbers
}