Have fun! I'd like to add that in practice I'd probably not go to these length to protect the variables unless it was absolutely necessary. I'd probably do something more like:
// This is the object we want to inherit from.functionBase(param1,_){var_this=this;varshared=_||{};// Declare class variables and functions like this:this.foo="Anyone can access this!";shared.bar=function(){console.log(secret());return"Shared function accessed!";};varsecret=function(){// _this is needed to access object in private functions, otherwise leave out.return_this.foo;};}// Inherits from BasefunctionDerived(param1){// Inheritvarshared={};Base.call(this,param1,shared);// Outputs "Shared function accessed!"console.log(shared.bar());}// Exclude shared param when not inheriting.varmyBase=newBase("param1");varmyDerived=newDerived("param1");
Yo use it the same, you just have to trust people not to pass in a _ argument on construction to snatch the shared variables. I think it's a step up from defining public variables like this._myProtectedVar, but it's not technically protected (which is why I call the variable shared inside the function).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Seems very promising. Now examining the code! :O
Have fun! I'd like to add that in practice I'd probably not go to these length to protect the variables unless it was absolutely necessary. I'd probably do something more like:
Yo use it the same, you just have to trust people not to pass in a
_
argument on construction to snatch the shared variables. I think it's a step up from defining public variables likethis._myProtectedVar
, but it's not technically protected (which is why I call the variableshared
inside the function).