模式 / 结构模式
image

//Adaptee
class StringList {
    constructor() {
        this.rows = [];
    }

    //SpecificRequest()
    getString() {
        return this.rows.join("\n");
    }

    add(value) {
        this.rows.push(value);
    }
}

//Adapter
class TextAdapter extends StringList {
    constructor() {
        super();
    }

    //Request()
    getText() {
        return this.getString();
    }
}

function getTextAdapter() {
    let adapter = new TextAdapter();
    adapter.add("line 1");
    adapter.add("line 2");
    return adapter;
}

//Client
let adapter = getTextAdapter();
let text = adapter.getText();
//text: line 1
//      line 2
console.log(text);