Created
March 17, 2015 07:45
-
-
Save bgadrian/4b02ee05956d43aa78f0 to your computer and use it in GitHub Desktop.
JS Prototype Inheritance while keeping own class name
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
//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; |
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
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