Created
March 1, 2014 19:37
-
-
Save vanmichael/9295892 to your computer and use it in GitHub Desktop.
Whats better javascript OOP notation?
This file contains 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
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