Last active
August 29, 2015 14:21
-
-
Save JonCatmull/3dd073fba32f7369c1a5 to your computer and use it in GitHub Desktop.
Guide for creating objects 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
var ExampleObject = function() | |
{ | |
var privateStaticMethod = function() {}; | |
var privateStaticVariable = "foo"; | |
var constructor = function ExampleObject(foo, bar) | |
{ | |
var = privateProperty = foo; | |
this.publicProperty = bar; | |
var privateMethod = function() {}; | |
this.publicMethod = function() {}; | |
}; | |
constructor.publicStaticMethod = function() {}; | |
return constructor; | |
}(); | |
ExampleObject.publicStaticMethod(); //calling a static method | |
var test = new ExampleObject(); //instantiation | |
test.publicMethod(); //calling a method | |
// http://stackoverflow.com/questions/1595611/how-to-properly-create-a-custom-object-in-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment