· 7 years ago · Apr 10, 2018, 02:56 AM
1// Leaving foo declaration global, since I don't know
2// whether you need it outside the scope of the closure.
3var foo = function() {};
4
5(function() {
6 // The closure has private variables if declared
7 // with "var ...".
8
9 // Adding event utility functions for event handlers
10 // by John Resig.
11 var addEvent = function( obj, type, fn ) {
12 if ( obj.attachEvent ) {
13 obj['e'+type+fn] = fn;
14 obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
15 obj.attachEvent( 'on'+type, obj[type+fn] );
16 } else
17 obj.addEventListener( type, fn, false );
18 };
19 var removeEvent = function( obj, type, fn ) {
20 if ( obj.detachEvent ) {
21 obj.detachEvent( 'on'+type, obj[type+fn] );
22 obj[type+fn] = null;
23 } else
24 obj.removeEventListener( type, fn, false );
25 };
26
27 // Here's your code.
28 var skeleton_init = function() {
29 // call some foo() code
30 };
31
32 // This code makes skeleton_init run after the
33 // document is done loading.
34 addEvent(document, 'load', skeleton_init);
35})();