Всем привет! Как спрятать служебный метод? При добавлении к дескриптору метода
ennumerable: false но в таком случае я не могу его использовать в других методах обьекта выкидывает ошибку "TypeError: this._load is not a function". Кто что посоветует?
"use strict"
var fs = require('fs');
function Settings(pathToJson) {
typeof pathToJson === "string" ? this.reload(pathToJson) : this.reload('./settings.json');
Object.defineProperties(this, {
_load: {enumerable: false},
settings: {enumerable: false}
});
Object.freeze(this);
}
Settings.prototype = {
reload: function(path){
this.settings = fs.readFileSync(path, 'utf-8');
this.settings = this.settings.replace(/\/\/.*/g, '');
this.settings = JSON.parse(this.settings);
},
_load: function(){
fs.writeFileSync('settings.json', JSON.stringify(this.settings, false, '\t'));
},
get include(){
return this.settings.include;
},
set include(arg){
if (arg instanceof Array) { // В том случае если передают массив
var _ = this;
arg.forEach(function(c, i){
// Если в массиве находятся не строки выкидывает ошибку!
if (!(typeof c === 'string')) throw new Error('Path not readable!');
// Если путь найден в инклудах или ексклудах путь не подключается!
if(~_.include.indexOf(c) || ~_.exclude.indexOf(c)) return;
// Создание инклуда и подключение путей
_.include = [];
_.include.push(c);
console.log('includig ' + c);
});
this._load(); // <== Здесь выскакивает ошибка
}
else if (typeof arg === 'string'){ // В том случае если передают один путь
if(~this.include.indexOf(arg) || ~_.exclude.indexOf(arg)) return;
this.include = []; // Создание инклуда и подключение путей
this.include.push(arg);
this._load(); // <== Здесь выскакивает ошибка
}
else throw new Error('Path not readable!');
},
get exclude(){
return this.settings.exclude;
}
}