Есть ли шаблон JavaScript, который имитирует свойства объекта "Защищенный", как то, что вы видите на таких языках, как С++?
В принципе, я хотел бы создать объект A, который имеет ряд "защищенных" свойств объекта, к которым можно получить ТОЛЬКО ТОЛЬКО от методов, которые определены из прототипа объекта A. ie - НЕдоступно публично из не-прототипированных методы A.
Например, в идеале было бы так:
function A(){
var prop1 = 1;
}
A.prototype.myFunc = function(){
var newVar = this.prop1; //newVar now is equivalent to 1
}
var instanceOfA = new A();
var newVar2 = instanceOfA.prop1; //error given as prop1 is "protected"; hence undefined in this case
BTW - Я не хочу, чтобы шаблон привилегированных функций-членов обращался к закрытым свойствам, поскольку функция-член остается общедоступной.