Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
Object.freeze not working on URL searchParams.set()

Is there a way to force an object to be recreated/cloned in order for it to be used specifically on the URL object?

I have tried using Object.freeze(new URL('http://example.com)), however, I can still add and remove searchParams to the object through url.searchParams.set('a', 'b').

I was expecting at least one of these to throw errors:

// Using freeze()
const url = Object.freeze(new URL('http://example.com'))
url.searchParams.set('a', 'b')
console.log(url.toString())

// Using seal()
const url2 = Object.seal(new URL('http://example2.com'))
url2.searchParams.set('c', 'd')
console.log(url2.toString())

// Also freezing the searchParams
const url3 = Object.freeze(new URL('http://example3.com'))
Object.freeze(url3.searchParams)
url3.searchParams.set('e', 'f')
console.log(url3.toString())

I would like to have a way where an error is thrown if the frozen object is used instead of cloned.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

There are two potential things tripping you up here:

Firstly, freezing an object doesn't freeze its sub-objects. It is not recursive. There are many implementations of a 'deep freeze' function that does work recursively, MDN's documentation on Object.freeze features one. This may or may not work on built-in types, where some properties are read-only (for example, you cannot execute url.searchParams = <new value>, this raises an error, which will probably break many implementations).

Secondly, setting or altering frozen objects doesn't raise an error unless you're in strict mode. Otherwise, the set just silently fails.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda