hzgt9b wrote:
I know how to overwrite a function. Normally this is what I would do:
function someFunction() { /* orig definition here */ }
//later in the execution stream I would do...
someFunction = function () { /* overwrite function definition */ }
The above works fine for me even when someFunction is originally
defined in a seperate frame other than the code that overwrites it
(obviously on the same domain).
What I don't know how to-do is overwrite a prototype function that
already loaded into memory on another frame (on the same domain). For
example:
//say, this prototype function is defined on a frame named
'frame1'
String.prototyp e.someOtherFunc tion() { /* define prototype
function here */ }
This is a syntax error. Prototype methods are defined like this instead:
String.prototyp e.someOtherFunc tion = function() {
// ...
};
Or like this, but that would overwrite all other methods and so is useful
for initialization of user-defined prototypes only:
String.prototyp e = {
someOtherFuncti on: function() {
// ...
}
};
You should avoid augmenting prototype objects of built-in objects for it
complicates programming a lot; String.prototyp e could be considered an
exception to this rule of thumb because for-in iteration over strings does
not yield useful results in all implementations and so one would probably
not use for-in then.
Problem is I don't know how to access the prototype function from
another frame.
window.parent.f rames["frame1"].Foo.prototype. bar
or
window.top.fram es["frame1"].Foo.prototype. bar
Depends on how deep your frameset is nested and where the method is defined.
I've tried
//assume we are not (executing) in 'frame1'
top.frame1.Stri ng.prototype.so meOtherFunction = function () { /*
overwrite function here */ }
This would accomplish what you want, but it would only affect the global
execution context of top.frame1, of course.
top.frame1.some OtherFunction = function () { /* overwrite
function here */ } //this just defines a new function in frame1
Actually, it only adds a property to top.frame1. It is
implementation-dependent whether this property will be available as a method
of the Global Object of the global execution context top.frame1 represents.
Is this possible? Can someone give me some pointers?
It does not make sense to overwrite a method in another global execution
context, unless this method is used in that execution context or subordered
local contexts.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>