This library is for an SPA (Single Page Application) page, as a learning project.
I am using the IIFE pattern, which is an immediately invoked function expression.
With this pattern we are going to...
var x = 1;
var func = (function(x) {
return x; // returns 1
})(x);
x = 6;
console.log(func); // 1
var func = (function() {
var x = 6;
var obj = {
getX: function() { return x; }
};
return obj;
})();
console.log(func.x); // 6
func.x = 8; // Creating a property in the object, but our property is on the function itselft.
console.log(func.x); // 6
var func = (function() {
var x = 6;
var obj = {
getX: function() { return x; }
};
if (typeof window.obj === 'undefined')
window.obj = window.$ = obj;
else
console.log('obj already exists!');
})();