Skip to content

Instantly share code, notes, and snippets.

@thisivan
Created January 19, 2010 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thisivan/281152 to your computer and use it in GitHub Desktop.
Save thisivan/281152 to your computer and use it in GitHub Desktop.
Creating Prototype objects with JavaScript
// Defining constructor function
function ObjectConstructor(message) {
// TODO: Add your own initialization code here
this.message = message || 'Hello Prototype World!';
};
// Defining an instance function
ObjectConstructor.prototype.sayHello = function() {
alert(this.message);
};
// Using your Prototype object
var object = new ObjectConstructor();
object.sayHello();
var object = new ObjectConstructor('Hello Mexpolk!');
object.sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment