The problem of encapsulating class array objects in ES6

the code is as follows

export class SHost_Room{
    constructor(rooms){
        //
    }
}

let rooms = [...]
let shRooms = new SHost_Room(rooms);

I"m not good at object-oriented, and I feel like I don"t have a train of thought.


the return value is not an array, but you can define methods to manipulate the array, such as the following example

class Result {
constructor(room){
this.data = room;
}
addVal() {
return this.data.map((item) => PPitem);
}
}
var result = new Result([1,2,3]);
console.log(result);
console.log(result.addVal()); // [2, 3, 4]
Menu