[removed] do primitive strings have methods?

前端 未结 2 1546
日久生厌
日久生厌 2020-11-28 13:09

MDN states:

primitive, primitive value

A data that is not an object and does not have any methods. JavaScript has 5 primitive datatypes: string, n

2条回答
  •  心在旅途
    2020-11-28 13:24

    The technically correct answer is "no".

    The real-world answer is "no, but it will work anyway". That's because when you do something like

    "s".replace()
    

    the interpreter knows that you want to actually operate on the string as if you had created it with

    var str = new String("s")
    

    and therefore acts as if you had done that.

提交回复
热议问题