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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:16:27+00:00 2026-06-14T13:16:27+00:00

The following program prints Hello world as expected var print = function(t){ document.write(t); };

  • 0

The following program prints “Hello world” as expected

var print = function(t){
  document.write(t);
};

var printAlias = print;

printAlias("Hello world");

But when I use the same technique with document.write it does not work.

var write = document.write ;
write("Something);

Can anybody tell me what am I missing?

  • 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-14T13:16:28+00:00Added an answer on June 14, 2026 at 1:16 pm

    It doesn’t work because you’ve lost the context (the “this value”) within the write method of document. You can invoke write with the call method to get it back:

    write.call(document, "Something");
    

    In your first example you are simply wrapping the call to document.write in another function, but the call itself keeps the context because you invoke write as a method of document.

    So you may as well stick with the usual or your wrapper function if it’s shorter code you were aiming for! Or (thanks @Esailija) you could bind the context to document at the time you create your write variable:

    var write  = document.write.bind(document);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following program, why does hitting the a key print hello, world while
In the following program, DummyMethod always print 5. But if we use the commented
What does the colon mean in the following Perl program? MAIN: { print Hello\n;
I would have expected the following C# program to only print EOF! once I
I am trying to understand the following: Given a small Hello World program in
Say I have the following c program: #include <stdio.h> int main() { printf(Hello world
The program below prints the following data: Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1 Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2 Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0 Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2 Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0 Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3 Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
To my surprise in the following program the Eclipse console doesn't print while in
When I write the following program: file 1: #include <stdio.h> int global; void print_global1()
Consider the following silly Perl program: $firstarg = $ARGV[0]; print $firstarg; $input = <>;

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.