Assigning document.writeln to object

Discussion in 'Javascript' started by Christopher Benson-Manica, Feb 10, 2005.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>test</title>
    </head>
    <body>
    <script type="text/javascript">
    try{
    var foo=document.writeln;
    foo( 'Hello, world!' );
    }
    catch( e ) {
    alert( e );
    }
    </script>
    </body></html>

    IE has no problem with this, but Firefox throws an exception -
    "Illegal operation on WrappedNative prototype object". Is it within
    its rights to do so?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Feb 10, 2005
    #1
    1. Advertising

  2. Christopher Benson-Manica wrote:


    > var foo=document.writeln;
    > foo( 'Hello, world!' );


    > IE has no problem with this, but Firefox throws an exception -
    > "Illegal operation on WrappedNative prototype object". Is it within
    > its rights to do so?


    Depends on the legal system of the country you are using Firefox in :).
    Seriously, writeln is a native method of the document object which if
    assigned to a global variable is no longer bound to the document object
    but the window object and calling writeln on the window doesn't make
    much sense.
    Why do you need that? Or what do you want to achieve, perhaps there are
    other ways to do that.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 10, 2005
    #2
    1. Advertising

  3. Martin Honnen <> spoke thus:

    > Depends on the legal system of the country you are using Firefox in :).
    > Seriously, writeln is a native method of the document object which if
    > assigned to a global variable is no longer bound to the document object
    > but the window object and calling writeln on the window doesn't make
    > much sense.


    Oh! Well, that explains it...

    > Why do you need that? Or what do you want to achieve, perhaps there are
    > other ways to do that.


    I don't, really - someone had suggested doing that in a previous post
    here, but the difference was that it was at function scope and so this
    issue wasn't relevant.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Feb 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tony
    Replies:
    6
    Views:
    2,981
  2. , India
    Replies:
    1
    Views:
    677
    Pascal J. Bourguignon
    Apr 22, 2008
  3. Jason Cook

    the difference between write and writeln

    Jason Cook, Oct 21, 2003, in forum: Javascript
    Replies:
    3
    Views:
    88
    Thomas 'PointedEars' Lahn
    Oct 21, 2003
  4. eels
    Replies:
    2
    Views:
    106
  5. weston
    Replies:
    1
    Views:
    253
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page