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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:46:50+00:00 2026-05-22T23:46:50+00:00

Can a shortcut not be made to methods such as document.createElement , document.createTextNode ,

  • 0

Can a “shortcut” not be made to methods such as document.createElement, document.createTextNode, [element].setSelectionRange etc?

var c = document.createElement;
var div = c('div');
div.innerHTML = 'blah';

document.body.appendChild(div);

When executing the above code Firebug console returns an error:

uncaught exception: [Exception… “Could not convert JavaScript argument” nsresult: “0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)” location: “JS frame :: http://fiddle.jshell.net/_display/ :: :: line 20″ data: no]

This happens on jsfiddle as provided here and silently fails when done outside of jsfiddle with no errors.

The below code works fine, so is it just limited to DOM manipulation methods?

function long_function_name(prop)
{
   alert(prop);
}

var c = long_function_name;

c('blah');

This has practical examples for compression sake:

Instead of:

if (element.setSelectionRange)
{
    element.setSelectionRange(pos, pos);
}

Compress to:

var s = element.setSelectionRange || 0;
if (s) s(pos, pos);
  • 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-22T23:46:51+00:00Added an answer on May 22, 2026 at 11:46 pm

    There are two obvious issues:

    • Calling your aliased functions will not be providing the correct this value (it will be the global object rather than document), which the DOM method may or may not depend upon;
    • DOM nodes in JavaScript are host objects, which are not subject to the normal rules of native JavaScript objects and can essentially do what they like. For example, there is no guarantee that a method of a host object is a regular Function object and may not therefore have the call() or apply() methods that you could otherwise use to provide the correct this value.

    This being the case, you’re better off writing a wrapper function instead, such as

    function c(tagName) {
        return document.createElement(tagName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application will have a per machine (not per user) Startup shortcut. I can
Is there a way to create a homescreen shortcut that can not be removed
Is there any button or shortcut that can make publish job instead of clicking
How can I remove a desktop shortcut by Innosetup? It's created by previous version
What is the shortcut key to clear console in Eclipse or how can it
Is there some way I can make the matlab integrated editor not use emacs
Someone can explain this error? Error Creating Control - head Object reference not set
In Windows 7, you can set a property of a shortcut to Run as
In vs2008, how can I (possibly with a macro) assign a shortcut key to
how can I launch programmatically an application from a Windows shortcut (.lnk file)? I

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.