-
-
Save KrofDrakula/336795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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