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

247
Vistas
javascript is there a way to override document?

document is part of browser api but still what if I want to override it though is there a way to force so as this triggers error

https://jsfiddle.net/4yuf5h2o/

  var document = {
      f: function() {
          alert('o')
      }
  }

  document.f();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not on the top level. In Chrome, for example, window.document is a nonconfigurable getter that returns the document:

console.log(Object.getOwnPropertyDescriptor(window, 'document'));

Since it's non-configurable, it can't be overwritten with anything else.

And you can't declare a new top-level identifier named document either, since it already exists. Use strict mode to make the error explicit:

'use strict';
const document = 'foo';

But you can declare a new variable named document inside an IIFE (so it's not on the top level).

(() => {
  var document = {
    f: function() {
      alert('o')
    }
  }

  document.f();
})();

about 4 years ago · Juan Pablo Isaza 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