Understand prototype in JavaScript (JavaScript prototype)

26 בפברואר 2008

תגיות:
תגובה אחת

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);    
הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

תגובה אחת

  1. Shay Jacoby26 בפברואר 2008 ב 23:50

    Thanks, Wonderful Post.
    I added a RSS Feed to your blog.

    הגב