Created
January 19, 2010 18:41
-
-
Save thisivan/281152 to your computer and use it in GitHub Desktop.
Creating Prototype objects with JavaScript
This file contains hidden or 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
// 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