Access public function from private function in JavaScript

泪湿孤枕 提交于 2019-12-07 15:44:26
a_pradhan

Look at this answer.

You wrap the public functions in an object literal and return it. You can thus call the private functions in the object literal functions.

You should read about hoisting and differences between declaring function and function expression.

Your code does not work because js knows that there is declared var publicFunctionSet (function expression) but it is not a function when privateFunction(x) is being declared.

PS. @Akash Pradhan answer will solve your problem, but I guess you still should check the background and undestand why it is not working the way you tried :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!