Skip to content

Instantly share code, notes, and snippets.

@ff6347
Created May 11, 2012 16:06
Show Gist options
  • Save ff6347/2660661 to your computer and use it in GitHub Desktop.
Save ff6347/2660661 to your computer and use it in GitHub Desktop.
a simple javascript object example
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;
}
};
};
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;
};
};
@ff6347
Copy link
Author

ff6347 commented May 11, 2012

This Gist is part of MT4D coming soon on fabiantheblind.info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment