Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created May 2, 2011 01:38
Show Gist options
  • Save liammclennan/951079 to your computer and use it in GitHub Desktop.
Save liammclennan/951079 to your computer and use it in GitHub Desktop.
Basic JavaScript Constructor
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