Connecting Tech Pros Worldwide Help | Site Map

question on Document.prototype modifications

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 4th, 2005, 11:05 PM
pierre.bru@gmail.com
Guest
 
Posts: n/a
Default question on Document.prototype modifications

hello,

I have a page made of a frameset that contains 2 frames.

if in that page I insert a new function in Document.prototype, will
this function be available in the already loaded frames ? if I reload
the frames after using via a <a target="somefame"..>, will the newly
loaded frame have access to the new function ?

TIA,
Pierre.


  #2  
Old November 6th, 2005, 04:15 AM
Joshie Surber
Guest
 
Posts: n/a
Default Re: question on Document.prototype modifications

> will this function be available in the already loaded frames

The frames will have different document.objects from the frameset page,
so the simple answer is no. If you were to say
frames[0].document.prototype then it would apply, but only as long as
the frame was showing the same page. As soon as a new page is loaded a
different document object is created, so you would need to redefine
document.prototype for each page viewed within the frameset.

Unless you are asking if the framed pages could call
top.document.prototypedMethod, in which case yes.

(Sorry for the messy grammer, it is sometimes better :-) )

  #3  
Old November 6th, 2005, 04:15 AM
Joshie Surber
Guest
 
Posts: n/a
Default Re: question on Document.prototype modifications

> will this function be available in the already loaded frames

The frames will have different document.objects from the frameset page,
so the simple answer is no. If you were to say
frames[0].document.prototype then it would apply, but only as long as
the frame was showing the same page. As soon as a new page is loaded a
different document object is created, so you would need to redefine
document.prototype for each page viewed within the frameset.

Unless you are asking if the framed pages could call
top.document.prototypedMethod, in which case yes.

(Sorry for the messy grammer, it is sometimes better :-) )

  #4  
Old November 6th, 2005, 05:35 PM
pierre.bru@gmail.com
Guest
 
Posts: n/a
Default Re: question on Document.prototype modifications

well... I expected Document.prototype to be a template copied into all
new documents created/loaded by the browser, espacially used when a
frame was (re)loaded... :(

thanks for your answer,
Pierre.

  #5  
Old November 7th, 2005, 09:15 AM
aundro
Guest
 
Posts: n/a
Default Re: question on Document.prototype modifications

"Joshie Surber" <joshiesurber@gmail.com> writes:
[color=blue][color=green]
>> will this function be available in the already loaded frames[/color]
>
> The frames will have different document.objects from the frameset page,
> so the simple answer is no. If you were to say
> frames[0].document.prototype then it would apply, but only as long as
> the frame was showing the same page. As soon as a new page is loaded a
> different document object is created, so you would need to redefine
> document.prototype for each page viewed within the frameset.[/color]

I don't think this is quite right.

[Ecma/Java]Script follows the prototype chain, which means if
'document.doSomething()' does not exist (that is: 'doSomething()' is
not a property of 'document'), it will next check into
'document.prototype'.

So, if you have access to the Document type (and it's prototype) in
order to modify it then yes, all your documents should show the
changes.

The following illustrates what I just said (in spidermonkey, just
changed the prompt's '>' to ':' to avoid quoting confusion in newsreaders):


-------------snip------------
aundro@paddy:~$ js
js: function Test () {}
js: var zzz = new Test ();
js: Test.prototype.showStuff = function () {print ("Hy there");}

function () {
print("Hy there");
}

js: zzz.showStuff();
Hy there
js:
aundro@paddy:~$
-------------snip------------


Arnaud

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.