Created
May 11, 2012 16:06
-
-
Save ff6347/2660661 to your computer and use it in GitHub Desktop.
a simple javascript object example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Gist is part of MT4D coming soon on fabiantheblind.info