Convert object to JSON omitting certain (private) properties

后端 未结 2 1528
陌清茗
陌清茗 2021-01-22 10:58

I\'ve been using dean edwards base.js (http://dean.edwards.name/weblog/2006/03/base/) to organise my program into objects ( base.js is amazing btw, if you havent used it before

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-22 11:23

    here is sample to to set variable visibility

    function Obj(){
           this.ref = 'public property'; // this property is public from within the object
    
           var ref = 'private proerty'; // this property is private.
    
           var self = this;
    
            this.showRef = function(){
                alert(ref);
                alert(self.ref);
            };
        }
    
    var obj = new Obj();
    obj.showRef();
    

提交回复
热议问题