String prototype modifying itself

后端 未结 4 2097
广开言路
广开言路 2021-02-20 16:09

As far as i know it\'s not possible to modify an object from itself this way:

String.prototype.append = function(val){
    this = this + val;
}

4条回答
  •  攒了一身酷
    2021-02-20 16:53

    While strings are immutable, trying to assign anything to this in any class will throw an error.

提交回复
热议问题