Skip to content

Instantly share code, notes, and snippets.

@carldanley
Last active November 23, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carldanley/ec2204682f7b01844e69 to your computer and use it in GitHub Desktop.
Save carldanley/ec2204682f7b01844e69 to your computer and use it in GitHub Desktop.
An example of the Prototype pattern in JavaScript
// build our blueprint object
var MyBluePrint = function MyBluePrintObject() {
this.someFunction = function someFunction() {
alert( 'some function' );
};
this.someOtherFunction = function someOtherFunction() {
alert( 'some other function' );
};
this.showMyName = function showMyName() {
alert( this.name );
};
};
function MyObject() {
this.name = 'testing';
}
MyObject.prototype = new MyBluePrint();
// example usage
var testObject = new MyObject();
testObject.someFunction(); // alerts "some function"
testObject.someOtherFunction(); // alerts "some other function"
testObject.showMyName(); // alerts "testing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment