Created
May 2, 2011 01:38
-
-
Save liammclennan/951079 to your computer and use it in GitHub Desktop.
Basic JavaScript Constructor
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
function Person(name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
Person.prototype = { | |
toString: function() { | |
return this.name + " is " + this.age + " years old."; | |
} | |
}; | |
var john = new Person("John Galt", 50); | |
console.log(john.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment