4 ms·
Would Object.create also inherit private functions and members ? No, it would not - these so-called private members and methods have nothing to do with inherit
by cygx 15y ago
Would Object.create also inherit private functions and members ?
No, it would not - these so-called private members and methods have nothing to do with inheritance, but rather lexical closure.
However, as the super constructor is called, priviledged methods will be present and still have access to the private variables.
See also http://stackoverflow.com/a/1441692/48015 http://stackoverflow.com/a/1441692/48015 for a more comprehensive overview over different access levels.
- chmike 15y agoThank you very much. It's the first time I see this pattern and a clear specification. I used privileged methods everywhere instead of shared public methods based on this article: http://javascript.crockford.com/private.html http://javascript.crockford.com/private.html The missing infos in the StackOverflow answer are how do one instantiate such class and access it's methods and public and shared members ? var obj = new MyObj() ? obj.publicSharedVar ?