OK. I have this lib for my internal project
(function() {
var window = this,
undefined; //guaranteed undefined
var h3 = window.h3 = function (user) { return window.h3 = new h3.prototype.init(user); };
h3.prototype = {
init: function(user) {
this.timestamp = +new Date;
this.user = user;
return this;
},
VERSION: '0.0.1', // Current version.
timestamp: undefined,
user: undefined,
a: function() {alert('a');}
};
h3.prototype.init.prototype = h3.prototype;
})();
Here is a usecase:
I need a lib that will store session user data and provide some functions for application like loading (via AJAX) information, display reports etc. Application is fully AJAX-driven. With help of jQuery i'll check for user credentials and init this lib with h3({user:'user_a',foo:'bar'})
call. Thus i will have a global object called h3 and can user it latter (say h3.a()
). If i need to re-init this object i can do it with h3.init({user:'user_b',foo:'bla-bla-bla'})
call.
Design inspired by well-known jQuery lib.
And main question is - how good/bad is this? Can you help me to validate this design?