Last active
December 14, 2015 08:28
-
-
Save mikespokefire/5057746 to your computer and use it in GitHub Desktop.
Object Orientated 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
"use strict"; | |
var MyClass = (function() { | |
function MyClass(publicString) { | |
this.publicString = publicString; | |
}; | |
var privateString = "I'm a private string that can't be accessed directly"; | |
// ============================================================================ | |
// | |
// CLASS METHODS | |
// | |
// ============================================================================ | |
MyClass.bar = function() { | |
console.log(helpMe()); | |
return 'bar'; | |
}; | |
// ============================================================================ | |
// | |
// INSTANCE METHODS | |
// | |
// ============================================================================ | |
MyClass.prototype.foo = function() { | |
console.log(helpMe()); | |
return 'foo'; | |
}; | |
return MyClass; | |
// ============================================================================ | |
// | |
// PRIVATE HELPER METHODS | |
// | |
// ============================================================================ | |
function helpMe() { | |
console.log(privateString); | |
return "I'm a private helper, I can't be accessed directly"; | |
}; | |
})(); | |
var c = new MyClass('a public string'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment