DCSIMG
Understand prototype in JavaScript (JavaScript prototype) - Client-Side with Basil Goldman

Understand prototype in JavaScript (JavaScript prototype)

Understand prototype in JavaScript

Hi Guy’s

Sorry on this syntaxed post, but I think for understand syntax you will read.
Follow my comments

Hope!!!


// Namespace core
function core() { return this.constructor('1.0.0.0'); }
core.prototype = {    
    // String type
    version:'',
    constructor: function(version){ this.version = version; },
    remote:{
        // Empty
    },
    web:{
      ui:{
        controls:{
            message:{
                show: function(value){ alert(value) }
            }
        }
      } 
    }
}; 

// Declare variables
// Inherit namespace core
var system = new core();
// controls is an object contain core.web.ui.controls 
var controls = system.web.ui.controls;

// Call to core.web.ui.controls.message.show() 
// using var controls
controls.message.show('Hello World!!!'); 

// Extend new function "hide" to 
// core.web.ui.controls.message
controls.message.constructor.prototype.hide = function() {
    // TODO
    controls.message.show('Im a hide() function in core.web.ui.controls.message');
} 

// Call to new function hide() extended in
// core.web.ui.controls.message using declared
// object system
controls.message.hide(); 

// Also you can extend write() function
system.web.ui.controls.message.constructor.prototype.write = function() {
    alert('write');
} 

// Call to new function write() extended in 
// core.web.ui.controls.message using declared object system
controls.message.write(); 

// Extend new namespace access to core.remote and 
// then extend new function get
system.remote.constructor.prototype.access = {
    get: function(){ alert('ok') }
} 

// Extend new variable of Array type in core.remote
system.remote.constructor.prototype.__last = [['0','0'],['1','1']];
// New variable of String type
system.remote.constructor.prototype.username = ''; 

// Call to core.remote.access.get()
system.remote.access.get(); 

// Alert __last variable length from core.remote.__last = []
alert(system.remote.__last.length);    


תגים:

Comments

# Shay Jacoby said:

Thanks, Wonderful Post.

I added a RSS Feed to your blog.

Tuesday, February 26, 2008 11:50 PM

Leave a Comment

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

Enter the numbers above: