Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created July 6, 2010 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/465295 to your computer and use it in GitHub Desktop.
Save ismasan/465295 to your computer and use it in GitHub Desktop.
/* Javascript classes, prototypes and method visibility
--------------------------------------------------------------*/
// Simple, prototype-less class
var Makoto = function(name){
function privateMethod(){
return 1;
}
this.pMethod = function(){
return privateMethod()
}
}
// Complex, prototype + private methods
var Abstract = function(){}
Abstract.prototype = {}
var Olly2 = (function(){
function privateMethod(){
return 1;
}
var klass = function(name){
}
klass.prototype = new Abstract
klass.prototype.hello = function(){
return privateMethod()
}
return klass;
})();
o = new Olly2('Olly')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment