fabianmoronzirfas
5/11/2012 - 4:06 PM

a simple javascript object example

a simple javascript object example

main();  
function main(){
   	var a = 23, b = 5;
   	var name = "Hello JS";
   	var result = compare(a,b);
       	alert("The Script named: "+ name +"\nCompared: "
       		  + a +" with "+ b +"\n" + result + " is bigger\n");
   	}
function compare (a,b){
   	if(a>b){
       	return  a;
       	}else{
       	return  b;
   	};
};
main(); // call the main function

function main(){ /* here wee go */

    var obj = new buildNewObject("Hello JS"); // create a new Object
    var a = 23, b = 5; // define the values
    obj.compare(a,b); // let the object compare the values
    // and make the message
    alert("The Script named: "+ obj.name + 
          "\nCompared: "+ a +" with "+ b +"\n" 
          + obj.result + " is bigger\n");
    obj = null; // delete the object
    return 0; // everything went fine return 0
};

function buildNewObject(n){/* this is our object builder*/
    this.name = n; /* its name is the incoming value*/
    this.result = 0;/* this will be set by the compare object*/
  
    this.compare = function(a,b){
        if(a > b){
            this.result = a;
            }else if(a < b){
            this.result= b;
            }
        };
    
};