Appearance mode is to provide a simple interface for the external one way, because the module internal methods are complex, can not be publicly disclosed, then we need a unified and simple external method (API) to invoke these intrinsic functions. At this point we can use the Appearance mode:
var module = (function () {var name = ' Bobi '; var _p = function () {//internal method, not public console.log (' Your name is ' + name);} var _q = function () {//internal method, not public console.log (' My name is ' + name);} var _c = function (m) {//internal method, do not expose name = M}return{f:function (m) {///public method _c (m);//Call Private method if (name = = ' Bobi ') {_p ()}else{_q ( ); }}} });
In module, all private methods do not need to be public, we just exposed an F method, as a bridge interface, F inside will execute call each internal method. We don't need to have a relationship with _q,_p's execution, just care about the public method of F. Here, F is used as a simple API to access these methods.
There are some drawbacks to the appearance pattern: that is, the performance problem of hierarchical access, which means that functions that could have been executed one level now need a second layer to implement, so when considering using this approach we have to consider the benefits and costs of doing so.
Javacript design mode-----appearance mode