正在加载视频...

视频加载失败

If you're still creating and modifying URLs in JavaScript using string concatenation, this is a PSA that there is a better way:

329,459 次观看 • 3 年前 •via X (Twitter)

10 条评论

Steve (Builder.io) 的头像
Steve (Builder.io)3 年前

Read more about using the URL constructor here:

ian.tsx 的头像
ian.tsx3 年前

If you prefer the immutable version: new URLSearchParams( Object.fromEntries({ key: "value", }) ) (Not sure if the Object.fromEntries is needed. It works in chrome without, but typescript requires it)

Fatih Aygün 的头像
Fatih Aygün3 年前

This is useful sometimes, especially for constructing the pathname component:

Shelton Louis 的头像
Shelton Louis3 年前

Keep making these videos. They are becoming very informative. What you just showed me was an eye-opener. I think I should look more into the tools I use everyday.

Url Sweatshirt 的头像
Url Sweatshirt3 年前

Damn my first thought for bugs was that you can’t use await outside of an async function.

Steve (Builder.io) 的头像
Steve (Builder.io)3 年前

You can as of recently!

Thai Pangsakulyanont 的头像
Thai Pangsakulyanont3 年前

Can also use URLSearchParams directly: `/api/v2/content?${new URLSearchParams({ model, locale, text })}`

Bao Huynh 的头像
Bao Huynh3 年前

Amazing video packed with content. I used to look at URL() constructor and wonder “why not just use template string”. Now I have realized the wrongs of mine.

Batuhan 的头像
Batuhan3 年前

Definitely like your content! What tool do you use for subtitles?

Anon Dev 的头像
Anon Dev3 年前

I love your content 😍

相关视频