Skip to content

Instantly share code, notes, and snippets.

@vanmichael
Created March 1, 2014 19:37
Show Gist options
  • Save vanmichael/9295892 to your computer and use it in GitHub Desktop.
Save vanmichael/9295892 to your computer and use it in GitHub Desktop.
Whats better javascript OOP notation?
var Maximum = function(array) {
this.array = array;
this.findMax = function (){
var maxValue = 0;
this.array.forEach(function(n) {
if (maxValue < n)
{
maxValue = n;
}
});
return maxValue;
};
};
//or
function Maximum(array) {
this.array = array;
this.findMax = function (){
var maxValue = 0;
this.array.forEach(function(n) {
if (maxValue < n)
{
maxValue = n;
}
});
return maxValue;
};
}
//Either way you call it the same
var person = new Minimum(ages);
person.findMax();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment