-
-
Save carldanley/ec2204682f7b01844e69 to your computer and use it in GitHub Desktop.
An example of the Prototype pattern in JavaScript
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
// 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