JavaScript, jquery

using prototype with javascript


// main class

var Call_ajax =  function()
{
this.first_name     = “Niraj”;
this.last_name      = “Maharjan”;
this.get_first_name = function()
{
return this.first_name;
}

this.get_last_name = function()
{
return this.last_name;
}

}

Call_ajax.prototype.get_full_name = function(){
return this.first_name+” “+this.last_name;
}

Call_ajax.prototype.greet = new function(){

this.greeting = function(my_greet)
{
if(my_greet == “Hi”)
console.log(‘hello’);
else if(my_greet == “Hello”)
console.log(‘Hi’);
else
console.log(‘Namastey’);
}
}

var apple = new function() {
this.type = “macintosh”;
this.color = “red”;
this.getInfo = function () {
return this.color + ‘ ‘ + this.type + ‘ apple’;
};
}

apple.green_apple = “this is a green apple”;

apple.mapple = function()
{
console.log(‘This is mapple funtion with in apple’);

}

apple.granee = new function()
{
this.lang = function()
{
console.log(‘This is granee funtion with in apple’);
}

}

//****************************************using in controller *******************************************

var init = new Call_ajax();

// calling member function
var first_name = init.get_first_name();
console.log(“First Name : “+ first_name);

// calling extended prototyped function
var full_name = init.get_full_name();
console.log(“Full Name : “+full_name);

// calling singlton function withing prototyped function
init.greet.greeting();

console.log(apple.color);
console.log(apple.green_apple);
apple.mapple();

apple.granee.lang();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s