Expose private variables in Revealing Module Pattern

后端 未结 3 1335
不知归路
不知归路 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

    var myRevealingModule = (function(){
    
        var name = 'Diogo';
    
        function setName () {
           name = name + ' Cardoso';
        };
    
        function getName () {
           return name;
        };
    
        return {
            fullName: name,
            set: setName,
            get: getName
        };
    
    }());
    

    http://jsfiddle.net/yeXMx/

提交回复
热议问题