Skip to content

Instantly share code, notes, and snippets.

@KrofDrakula
Forked from anonymous/gist:336447
Created March 18, 2010 19:55
Show Gist options
  • Save KrofDrakula/336795 to your computer and use it in GitHub Desktop.
Save KrofDrakula/336795 to your computer and use it in GitHub Desktop.
// Leaving foo declaration global, since I don't know
// whether you need it outside the scope of the closure.
var foo = function() {};
(function() {
// The closure has private variables if declared
// with "var ...".
// Adding event utility functions for event handlers
// by John Resig.
var addEvent = function( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
};
var removeEvent = function( obj, type, fn ) {
if ( obj.detachEvent ) {
obj.detachEvent( 'on'+type, obj[type+fn] );
obj[type+fn] = null;
} else
obj.removeEventListener( type, fn, false );
};
// Here's your code.
var skeleton_init = function() {
// call some foo() code
};
// This code makes skeleton_init run after the
// document is done loading.
addEvent(document, 'load', skeleton_init);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment