From a537721ea120296e0990f515e75765936cbe0fd1 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 20 Apr 2014 02:53:02 -0400 Subject: [PATCH] Added documentation for implicit private members --- doc/mkeywords.texi | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/mkeywords.texi b/doc/mkeywords.texi index 7affa50..6833040 100644 --- a/doc/mkeywords.texi +++ b/doc/mkeywords.texi @@ -1,5 +1,5 @@ @c This document is part of the GNU ease.js manual. -@c Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc. +@c Copyright (C) 2011, 2013, 2014 Mike Gerwitz @c Permission is granted to copy, distribute and/or modify this document @c under the terms of the GNU Free Documentation License, Version 1.3 or @c any later version published by the Free Software Foundation; with no @@ -23,13 +23,15 @@ The table below summarizes the available keywords accepted by @headitem Keyword @tab Description @item @code{public} @tab Places member @var{name} into the public API for @var{C} (@pxref{Access -Modifiers}). +Modifiers}); this is the default visibility. @item @code{protected} @tab Places member @var{name} into the protected API for @var{C} (@pxref{Access Modifiers}). @item @code{private} @tab Places member @var{name} into the private API for @var{C} -(@pxref{Access Modifiers}). +(@pxref{Access Modifiers}); this is done implicitly if the member name is +prefixed with an underscore, unless another access modifier is explicitly +provided. @item @code{static} @tab Binds member @var{name} to class @var{C} rather than instance of @var{C}. Member data shared with each instance of type @var{C}. @@ -97,7 +99,7 @@ Not accessible outside of @var{C} or any instance of @var{C}. @emph{Not} @tab Places member @var{name} in public interface (accessible outside of @var{C} or instance of @var{C}; accessible by subtypes). Implied if no other access -modifier is provided. +modifier is provided (but see @code{private}); @item @code{protected} @tab Places member @var{name} in protected interface (accessible only within @@ -105,7 +107,9 @@ Places member @var{name} in protected interface (accessible only within @item @code{private} @tab Places member @var{name} in private interface (accessible only within -@var{C} or instance of @var{C}; not accessible by subtypes). +@var{C} or instance of @var{C}; not accessible by subtypes); implicit if the +member name is prefixed with an underscore, unless another access modifier +is explicitly provided. @end multitable @caption{Access modifiers} @end float @@ -118,7 +122,9 @@ Only one access modifier may appear in @var{keywords} for any given @var{name}. @item If no access modifier is provided in @var{keywords} for any member -@var{name}, member @var{name} is implicitly @code{public}. +@var{name}, member @var{name} is implicitly @code{public}, unless the member +name is prefixed with an underscore, in which case it is implicitly +@code{private}. @end itemize @menu @@ -146,6 +152,12 @@ class. Public properties, however, should be less common in practice for a very important reason, which is explored throughout the remainder of this section. +Following common conventions in modern object-oriented languages, members +with an underscore prefix (e.g. @code{_foo}) are implicitly private; this +behavior can be overridden by explicitly specifying an access modifier. This +convention allows for more concise member definitions and is more natural to +those who use JavaScript's native prototype model. + @anchor{Encapsulation} @subsubsection Encapsulation @dfn{Encapsulation} is the act of hiding information within a class or