1

I've read about how to make a JS namespace, but my question is how can I make sure the functions inside would only happen on page load? i.e. instead of:

$(document).ready(function () {...});

(or any other lib then jquery).

also - is there a way to control what will launch on page load and what would before?

Thank you!:)

FED
  • 319
  • 1
  • 2
  • 12

2 Answers2

0

The following example uses an immediate-function to encapsulate the Code and registers an event-handler on the event DOMContentReady which fires when the Browser has the DOM ready but bevor Images are loaded.

(function () {
  'use strict';

  var
  init = function () {
    window.console.info('init()');
  };

  window.addEventListener('DOMContentReady', init, false);
}());

The immediate-function gets executet as soon as the browser loads the code. From that point there are different events on which further code-execution can be scheduled.

Without using a framework like jquery, which puts some effort in this toppic, you have to handle different events in different browser by your own.

phylax
  • 2,034
  • 14
  • 13
0

put this code out of jquery code

 var MyReallyCoolLibrary = {
awesome: "stuff",
doSomething: function() {
},
doAnotherThing: function() {
}

};

   MyReallyCoolLibrary.awesome;

   alert(MyReallyCoolLibrary.awesome);
li bing zhao
  • 1,388
  • 13
  • 12