Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 610085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:38:14+00:00 2026-05-13T17:38:14+00:00

Original source: http://twitter.com/tobeytailor/status/8998006366 (x=[].reverse)() === window // true I’ve noticed that this behavior affects

  • 0

Original source: http://twitter.com/tobeytailor/status/8998006366

(x=[].reverse)() === window // true

I’ve noticed that this behavior affects all the native types. What exactly is happening here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:38:14+00:00Added an answer on May 13, 2026 at 5:38 pm

    This is to do with the weird way this binding works in JavaScript.

    [].reverse
    

    is the method reverse on an empty list. If you call it, through one of:

    [].reverse();
    []['reverse']();
    ([].reverse)();
    

    then it executes with this bound to the list instance []. But if you detach it:

    x= [].reverse;
    x();
    

    it executes with no this-binding, so this in the function points to the global (window) object, in one of JavaScript’s worst, most misleading design mistakes.

    (x=[].reverse)()
    

    Is also doing the detach. The assignment operator returns the same function object it was passed so it looks like it’s doing nothing, but it has the side-effect of breaking the limited special case that causes JavaScript to bind this.

    So you are saying:

    Array.prototype.reverse.call(window)
    

    reverse, like many other Array.prototype methods, is defined by ECMAScript to work on any native sequence-like object. It reverses the items with number-string keys (up to object.length) and returns the object. So it’ll return the object that was passed in for any type that has a length property.

    window has a length property, which corresponds to window.frames.length, so calling this method with this pointing at window will work and return the window. In theory it may still fail, because:

    1. window is allowed to be a “host object” rather than a “native object”; in this case the guarantees about what you can pass to other prototypes’ methods don’t necessarily apply; and
    2. if the window actually has frames/iframes, it would try to reverse their order, which wouldn’t work because the frame collection is read-only.

    However, in current browsers the former case does work and the latter fails silently without an error, so you still get the ===window behaviour and not an Exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.