• 返回: {string}

    URL 对象上调用 toJSON() 方法将返回序列化的 URL。 返回值与 [url.href] 和 [url.toString()] 的相同。

    URL 对象使用 [JSON.stringify()] 序列化时将自动调用该方法。

    1. const myURLs = [
    2. new URL('https://www.example.com'),
    3. new URL('https://test.example.org')
    4. ];
    5. console.log(JSON.stringify(myURLs));
    6. // 打印 ["https://www.example.com/","https://test.example.org/"]