Just like C# or Java to put all my jQuery code in one .js file, something like this:
namespace MySite
{
class HomePage
{
function Init(params) { /*...*/ }
//...
}
class ContactForm
{
function Validate() { /*...*/ }
//...
}
}
So you can call it in this way:
$(function () {
MySite.HomePage.Init({a : "msg"});
});
I have this code, but doesn't work:
$.namespace = function () {
var a = arguments, o = null, i, j, d;
for (i = 0; i < a.length; i = i + 1) {
d = a[i].split(".");
o = window;
for (j = 0; j < d.length; j = j + 1) {
o[d[j]] = o[d[j]] || {};
o = o[d[j]];
}
}
return o;
};
$.namespace('$.mysite');
$.mysite.Home = function () {
function Home(params) {
//...
};
Home.prototype = function () {
Init: function () {
alert("lol");
}
}
};
Is it possible to that in jQuery? (something similar or recommendations / examples to keep my jquery code organized. ) Thanks for your time and answers (sorry for my bad english).