Does JavaScript have a built in stringbuilder class?

前端 未结 10 1615
Happy的楠姐
Happy的楠姐 2020-11-30 19:33

I see a few code project solutions.

But is there a regular implementation in JavaScript?

10条回答
  •  再見小時候
    2020-11-30 20:19

    That code looks like the route you want to take with a few changes.

    You'll want to change the append method to look like this. I've changed it to accept the number 0, and to make it return this so you can chain your appends.

    StringBuilder.prototype.append = function (value) {
        if (value || value === 0) {
            this.strings.push(value);
        }
        return this;
    }
    

提交回复
热议问题