Expose private variables in Revealing Module Pattern

后端 未结 3 1376
不知归路
不知归路 2021-02-04 11:29

I\'m trying to implement the Revealing Module Pattern but I\'m unable to expose a modified private property.

var myRevealingModule = (function(){

    var name =         


        
3条回答
  •  半阙折子戏
    2021-02-04 12:21

    return {
        fullName: name,
        set: setName
    };
    

    That uses the values of name and setName. It does not create a reference to the variable. Effectively, name is copied.

    You need to create a corresponding getName method, to take advantage of closures so that you can keep a reference to a variable.

提交回复
热议问题