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

  • Home
  • SEARCH
  • 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 9273975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:14:32+00:00 2026-06-18T16:14:32+00:00

I just read the John Resig article about overriding the globals in browser (e.g.

  • 0

I just read the John Resig article about overriding the globals in browser (e.g. Array) but when I try that example in my browser, nothing happend.

Here the code:

var sec = {};
function Array() { 
    alert(1); 
    sec = this; 
}; 

and when I run ["zdxc", "sd", 1111, 11.1] in my browser’s console, nothing happend. Array declared and no alert shown.

Is that a bug that fixed in modern browsers or it’s still works in some version of browsers?

  • 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-06-18T16:14:34+00:00Added an answer on June 18, 2026 at 4:14 pm

    Thats because you override the Array-contructor which makes the call new Array(); return your custom object insted of an actual Array.

    So calling

    var arr = ["zdxc", "sd", 1111, 11.1];
    

    makes arr beeing a native Array.

    Calling

    var arr_override = new Array();
    

    makes arr_override beeing an Object of the type you declared before and therefore executing your alert-statement. Overriding the constructor kind of “erases” the Array-initialisation from the identifier replacing it with your constructor function. Its not an actual Array.

    According to the answer to this question the Array-Literal ([]) is not beeing affected by this behaviour since about 2008 in all mayor browsers..

    EDIT:

    After trying around a bit it does not seem to be possible to modify the behaviour of the []-notation and it is not recomended either to modify Native Objects (expecially their constructors) at all btw.

    How ever it is possible to extend the prototypes and also to modify existing properties/methods like in the example below

    var arr = [];
    arr.push('2323');
    alert(arr);
    
    Array.prototype.push = function() { alert('trololololo'); }
    arr.push(123);
    

    Hope this helps. Cheers!

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

Sidebar

Related Questions

I've just read in a file that is something like: name: john, jane car:
I just read an article on www.songho.ca which indicates that a projection matrix is
I just read this article from Google. I always thought that closing tags is
I just read the Wikipedia article on mock objects , but I'm still not
I just read in Code Complete that you should not use exceptions for flow
I just read a blog which says ...methods that couldn’t be inlined previously because
I just read this great answer from BalusC about how to upload files with
I just read about the breadth-first search algorithm in the Introduction to Algorithms book
I just read about HTML 5's WebSocket interface. How can I start trying this?
I read John Robbins' article TFS 2010 Build Number and Assembly File Versions: Completely

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.