Skip to content

Instantly share code, notes, and snippets.

@krhoyt
Created December 24, 2014 19:57
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 krhoyt/7735b967d53eccf554ba to your computer and use it in GitHub Desktop.
Save krhoyt/7735b967d53eccf554ba to your computer and use it in GitHub Desktop.
Basic OOP template for JavaScript libraries.
// Originally
// http://phrogz.net/js/classes/OOPinJS.html
function Proxy()
{
// Private variables and methods
// Only priveleged
var MY_PRIVATE = "PRIVATE";
var moar_private = null;
function doSomethingPrivate()
{
console.log( "Something private." );
}
// Priveleged methods
// Invoke publicly
// Access to private
this.doPriveleged = function( value )
{
console.log( "Priveledged." );
doSomethingPrivate()
};
// Public properties
this.public_property = "Public.";
}
// Public methods
Proxy.prototype.doSomethingPublic = function() {
console.log( "Something public." );
};
// Prototype properties
Proxy.prototype.stuff = "Stuff.";
// Static properties
Proxy.MOAR_STUFF = "Moar stuff.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment