Skip to content

Instantly share code, notes, and snippets.

@JonCatmull
Last active August 29, 2015 14:21
Show Gist options
  • Save JonCatmull/3dd073fba32f7369c1a5 to your computer and use it in GitHub Desktop.
Save JonCatmull/3dd073fba32f7369c1a5 to your computer and use it in GitHub Desktop.
Guide for creating objects in JavaScript
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