Skip to content

Instantly share code, notes, and snippets.

@bgadrian
Created March 17, 2015 07:45
Show Gist options
  • Save bgadrian/4b02ee05956d43aa78f0 to your computer and use it in GitHub Desktop.
Save bgadrian/4b02ee05956d43aa78f0 to your computer and use it in GitHub Desktop.
JS Prototype Inheritance while keeping own class name
//in console log and memory profiler, the Child name will appear instead of Master.
var Child = function(){
//call the parents construct, he knows what to do
this._construct.apply(this, arguments);
};
Child.prototype = new Master(true);//one instance of Master will always be in memory as a prototype
Child.prototype.OnInit = function(params){};
Child.prototype.ownProperty = null;
var Master = function(notRealInstance){
if (typeof(notRealInstance) !== 'undefined' && notRealInstance === true){
return;
}
this._construct.apply(this, arguments);
};
Master.prototype = {
myOwnProperty: null,
_construct:function(params){ this.OnInit(params); },
OnInit: function(){},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment