This article is an original article, if you want to reprint, please indicate the source of the article
The main idea is to only open common properties and methods when inheriting, and not to open other functions, so as to realize the function of private.
functionA () { This. x = 100; This. y = 200; This. F =function() {Console.log ( This. x + This. Y); }
Private Functions This. G =function() {Console.log ( This. x- This. Y); }}functionC () {varA =NewA (); varo =NewObject (); O.x=a.x; O.y=a.y; O.F=A.F; returno;}functionB () {}b.prototype=C ();functionrun () {varb =NewB (); B.f ();}
The function of the C function is to eliminate the private function in a (g), the other properties and methods into the O object return, and then the prototype B is assigned to the object returned by C, so that when the B object is generated, only access to x,y,f, thus implementing the Private function g
JS implements private functions through inheritance