Skip to content

Instantly share code, notes, and snippets.

@agbishara
Created November 23, 2014 18:40
Show Gist options
  • Save agbishara/db321262401429424022 to your computer and use it in GitHub Desktop.
Save agbishara/db321262401429424022 to your computer and use it in GitHub Desktop.
http://jsperf.com/asdffafaal/2
// Define a class like this
function Person(name, gender){
// Add object properties like this
this.name = name;
this.gender = gender;
}
// Add methods like this. All Person objects will be able to invoke this
Person.prototype.speak = function(){
alert("Howdy, my name is" + this.name);
};
// Instantiate new objects with 'new'
var person = new Person("Bob", "M");
// Invoke methods like this
person.speak(); // alerts "Howdy, my name is Bob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment