var MyObj = (function() { // This is like a namespace var privateSharedVar = 'private shared value - (Java: private static)'; function privateSharedFunction() { alert('Private shared function - (Java: private static)'); } function MyObj() { // This is a public constructor var privateInstanceVar = 'Private instance value - Java: private'; this.publicInstanceVar = 'Public instance value - Java: public'; function privateInstanceFunction() { alert('Private instance function - (Java: private method)'); }; this.publicInstanceMethod = function() { alert('Public instance function - (Java: public method)'); }; } MyObj.prototype.publicSharedVar = 'Public shared value - (Java: public static)'; MyObj.prototype.publicSharedMethod = function() { alert('Public shared function - (Java: Public static method)') }; return MyObj; })();
In this code we have all these levels:
- Private fields
- Public fields
- Private methods
- Public methods
- Private static fields
- Public static fields
- Private static methods
- Public static methods
No comments:
Post a Comment