DCSIMG
How to write JavaScript right? - Client-Side with Basil Goldman

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'); }

תגים:

Comments

# shay said:

Which include fle (script src) do you need in order to run this code?

can you please attach a working example files?

Tuesday, February 19, 2008 10:41 PM
# Basil Goldman said:

This is just an example I have created to pass the main concept of Prototype. If you want to know more about it, I can give you some directions.

Wednesday, February 20, 2008 12:57 PM
# Shay Jacoby said:

Sure, I want to know more about it.

I think that the best way to understand new stuff is to play with a working example.

I'd like to get some good links about it:

my email: shayja (in gmail)

thanks.

Monday, February 25, 2008 3:07 PM

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: