Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>this is how i do mine:</p> <pre><code> ;(function (window) { "use strict"; //-- Private Vars var opt, obj, rm, Debug; //-- construtor function App(requestedMethod) { //-- set up some vars if(typeof requestedMethod !== 'undefined') { rm = requestedMethod; } opt = { rMethod: (typeof rm !== 'undefined') ? (rm != null) ? rm : false : false } //-- containe resulable objects obj = {} //-- call the init method this.init(); } /** Public Methods **/ /** * The Init method called on every page load */ App.prototype.init = function () { var om = opt.rMethod; //-- Once all init settings are performed call the requested method if required if(om) {(typeof App.prototype[om] == 'function') ? App.prototype[om]() : _DB('Call to Method [' + om + '] does not exsist.');} }; /** * testmethod */ App.prototype.testmethod = function () { }; /** Private Methods **/ function PrivateMethod(){ } /** * A console output that should enable to remain enable js to work in IE * just incase i forget to remove it when checking on those pesky IE browsers.... */ function _DB(msg){ if(window.console &amp;&amp; window.console.log){ var logDate = new Date(); window.console.log('------------------- ' + logDate + ' ----------------------------------'); window.console.log(msg); } }; window.App = App; })(window); </code></pre> <p>then call it like:</p> <pre><code> &lt;script src="ptha/to/your/app.js"&gt;&lt;/script&gt; &lt;script&gt;$(function() { new App('testmethod'); });&lt;/script&gt; </code></pre> <p>When the code is loaded the new App() will then run once all page load data has completed</p> <p>Hope this helps.To get access to it outside add the new to a var</p> <pre><code> var App = new App('testmethod); </code></pre> <p>then you can access things like</p> <pre><code> App.testmethod()... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload