2022년 2월 14일 월요일

javascript - StringBuilder

 

String builder for JavaScript

function StringBuilder(value) {
    this.strings = new Array();
    this.append(value);
}
StringBuilder.prototype.append = function(value) {
    if (value) {
        this.strings.push(value);
    }
}
StringBuilder.prototype.clear = function() {
    this.strings.length = 0;
}
StringBuilder.prototype.toString = function() {
    return this.strings.join("");
}
var sb = new StringBuilder();
sb.append("This is");
sb.append("much better looking");
sb.append("than using +=");
// joins the string
var myString = sb.toString();
// Cleans out the string buffer in the StringBuilder.
// This effectively makes it empty in case you did not
// know what cleaning out a buffer in this context
// meant.
sb.clear();
JavaScript

    출처 : https://www.c-sharpcorner.com/blogs/is-there-a-way-to-implement-a-stringbuilder-in-javascript2



    댓글 없음:

    댓글 쓰기

    Flutter #0

    [Flutter 교육] Dart vs JavaScript 타입 시스템 비교 1. 기본 타입 차이 숫자 타입 // Dart int integerNumber = 42; // 정수 double floatingPoint = 3.14; // 부...