How to write JavaScript right?
Ok guy's.
We are having 3 ways (Prototype, Object and Closure) to write JavaScript but I like at once strong and beautiful "Prototype".
Here attached example for Prototype way (with Namespaces, Classes and Methods as in C#).
// Namespace Core
function core() { return this.constructor('release 1.2.3'); }
core.prototype = {
version:'',
constructor: function(version) { this.version = version },
remote:{
access:{
get:function(url, data, callback) {
// Do
}
}
},
web:{
ui:{
init:function() {},
controls:{
message:{
show: function(title, context) {
// Do
}
}
}
}
},
user:{
info:{
get: function(userName) {
var property = [];
property = this.prototype.remote.access.get('http://',{rq:userName}, function(){ });
return property;
}
},
remove: function(userName) {
// Do
}
}
};
// Declare
var system = new core();
var userProperty = system.user.info.get('Administrator');
if(userProperty.length > 0) { system.web.ui.controls.message.show('Hello World!!!','Text'); }