Created
June 6, 2013 19:27
-
-
Save Arsenalist/5724203 to your computer and use it in GitHub Desktop.
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
// #1 - Using a function | |
function Apple (country) { | |
this.country = country; | |
this.color = "red"; | |
this.getInfo = getAppleInfo; | |
} | |
function getAppleInfo() { | |
return this.country + ' has ' + this.color + 'apples'.; | |
} | |
// #2 - Using the prototype | |
function Apple (country) { | |
this.country = country; | |
this.color = "red"; | |
} | |
Apple.prototype.getInfo = function() { | |
return this.country + ' has ' + this.color + 'apples'.; | |
}; | |
// #3 - Using object literals | |
var apple = { | |
country: "Sweden", | |
color: "red", | |
getInfo: function () { | |
return this.country + ' has ' + this.color + 'apples'.; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment