Assigning document.writeln to object

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

<!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?
 
M

Martin Honnen

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.
 
C

Christopher Benson-Manica

Martin Honnen said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top