location.href property vs. location.assign() method

后端 未结 5 2025
名媛妹妹
名媛妹妹 2020-12-05 09:17

Is there any particular advantage/disadvantage in JavaScript memory consumption between using location.href = url as opposed to location.assign(url)

5条回答
  •  日久生厌
    2020-12-05 09:44

    I personally prefer calling the function instead, because calling a function gives me a better impression that something is running and that is not only a value of a variable that is changing.

    But probably yes, it may be true that location.href = url; is faster than location.assign(url), although it may depend on the JavaScript engine implementation, see the test I've just created.

提交回复
热议问题