Javascript private member on prototype

前端 未结 8 941
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 01:15

Well I tried to figure out is this possible in any way. Here is code:

a=function(text)
{
   var b=text;
   if (!arguments.callee.prototype.get)
      argumen         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 01:43

    I know this thread is really really old now, but thought this solution might be of interest to anyone passing by:

    const Immutable = function ( val ) {
        let _val = val;
    
        this.$ = {
            _resolve: function () {
                return _val;
            }
        };
    };
    Immutable.prototype = {
        resolve: function () {
            return this.$._resolve();
        }
    };
    

    Essentially hiding the internal _val from being manipulated and making an instance of this object immutable.

提交回复
热议问题