Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!