//-------------------------------------------------------------------------
// sample1: jQuery style of export
(function(window, undefined) { var query = function() { throw new Error("hop"); } window.query = query; })(window); window.onload = function() { try { query(); } catch (ex) { //??? alert(ex.message); } } //-------------------------------------------------------------------------// sample1: exporting to "custom namespace" not window var ns = {}; (function(window, undefined) { var query = function() { throw new Error("hop"); } window.query = query; })(ns); window.onload = function() { try { ns.query(); } catch (ex) { //??? alert(ex.message); } } //-------------------------------------------------------------------------// plain old "global scope method" var query = function() { throw new Error("hop"); } window.onload = function() { try { query(); } catch (ex) { //??? alert(ex.message); } }
Final fix ? export,import
(function(window, undefined) { var query = function() { throw new Error("hop"); } window.query = query; })(window); window.onload = function() { var query = window.query; try { query(); } catch (ex) { //??? alert(ex.message); } }
No comments:
Post a Comment