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 254107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:49:08+00:00 2026-05-11T21:49:08+00:00

I was just reading this question and wanted to try the alias method rather

  • 0

I was just reading this question and wanted to try the alias method rather than the function-wrapper method, but I couldn’t seem to get it to work in either Firefox 3 or 3.5beta4, or Google Chrome, both in their debug windows and in a test web page.

Firebug:

>>> window.myAlias = document.getElementById
function()
>>> myAlias('item1')
>>> window.myAlias('item1')
>>> document.getElementById('item1')
<div id="item1">

If I put it in a web page, the call to myAlias gives me this error:

uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: file:///[...snip...]/test.html :: <TOP_LEVEL> :: line 7" data: no]

Chrome (with >>>’s inserted for clarity):

>>> window.myAlias = document.getElementById
function getElementById() { [native code] }
>>> window.myAlias('item1')
TypeError: Illegal invocation
>>> document.getElementById('item1')
<div id=?"item1">?

And in the test page, I get the same “Illegal invocation”.

Am I doing something wrong? Can anyone else reproduce this?

Also, oddly enough, I just tried and it works in IE8.

  • 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-11T21:49:08+00:00Added an answer on May 11, 2026 at 9:49 pm

    You have to bind that method to the document object. Look:

    >>> $ = document.getElementById
    getElementById()
    >>> $('bn_home')
    [Exception... "Cannot modify properties of a WrappedNative" ... anonymous :: line 72 data: no]
    >>> $.call(document, 'bn_home')
    <body id="bn_home" onload="init();">
    

    When you’re doing a simple alias, the function is called on the global object, not on the document object. Use a technique called closures to fix this:

    function makeAlias(object, name) {
        var fn = object ? object[name] : null;
        if (typeof fn == 'undefined') return function () {}
        return function () {
            return fn.apply(object, arguments)
        }
    }
    $ = makeAlias(document, 'getElementById');
    
    >>> $('bn_home')
    <body id="bn_home" onload="init();">
    

    This way you don’t loose the reference to the original object.

    In 2012, there is the new bind method from ES5 that allows us to do this in a fancier way:

    >>> $ = document.getElementById.bind(document)
    >>> $('bn_home')
    <body id="bn_home" onload="init();">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 177k
  • Answers 177k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What do you use for the actual http download? I… May 12, 2026 at 3:28 pm
  • Editorial Team
    Editorial Team added an answer The security concerns that you mention aren't, per se, about… May 12, 2026 at 3:28 pm
  • Editorial Team
    Editorial Team added an answer There are multiple WAP Simulators available; an online example is… May 12, 2026 at 3:28 pm

Related Questions

Alright. So I wanted to use a file written in c in c++. I
I was just reading about Linq to SQL being discontinued. For a while I
Recently, I've got a dangerous idea into my head after reading this blog post.
Am I correct in assuming that if you have an object that is contained

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.