You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RyanCavanaugh
removed
the
Canonical
This issue contains a lengthy and complete description of a particular problem, solution, or design
label
Feb 1, 2016
@yortus Either way is duplicated or not, the solution of private methods would be fine. As you can see, it really hiddes the method but it continues using the this keyword. Besides, private methods should stay as the name says 'only for the class' and Typescript compilation supports it! But that method can be consumed by normal Javascript because is inside the prototype of the class.
Please take a look at this example:
(function(){varPerson=(function(){functionsecretMessage(){return"Hi "+this.name+" "+this.lastName;}functionPerson(name,lastName){this.name=name;this.lastName=lastName;}Person.prototype.greet=function(){returnsecretMessage.call(this);};returnPerson;}());varc=newPerson("Santiago","Aguilar");console.log(c.greet());//will greet :)console.log(c.secretMessage());//ey ey this function is private, and can't be reached! Because it's private!})();
Pretty much like the title says, private methods should stay private:
input:
actual output:
expected output:
The text was updated successfully, but these errors were encountered: