473,748 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how can I overwrite a prototype function?

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 */ }

Problem is I don't know how to access the prototype function from
another frame. I've tried
//assume we are not (executing) in 'frame1'
top.frame1.Stri ng.prototype.so meOtherFunction = function () { /*
overwrite function here */ }
top.frame1.some OtherFunction = function () { /* overwrite
function here */ } //this just defines a new function in frame1

Is this possible? Can someone give me some pointers?
Jun 27 '08 #1
2 6462
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>
Jun 27 '08 #2
On Jun 7, 2:03*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
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.prototy pe.someOtherFun ction() { /* 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.Str ing.prototype.s omeOtherFunctio n = 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.som eOtherFunction = 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>- Hide quoted text -

- Show quoted text -
Thanks for the reply and info.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3758
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the bind function. The problem with Javascript is that the "this" operator is poorly overloaded and it is often hard to understand in the context of object-oriented javascript So, let's start with the definition:
8
2060
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
2
3033
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass' priviledged methods also. Do you know if this is possible ? In the following example, I create an ObjectA (variable a), an ObjectB which inherits ObjectA (variable b) and an ObjectC which inherits ObjectA (variable c1). The 'toString ()' method...
4
1770
by: lkrubner | last post by:
I'm reading an essay, I think one of Crockford's, and it has this example in it: function Demo() { } Demo.prototype = new Ancestor(); Demo.prototype.foo = function () { } ; Does Ancestor now have a function called foo? What if I have 5 different objects, all descended from Ancestor? Do
21
3851
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one would only really need to use a function
13
2572
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
5
2242
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
6
1884
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance" using the prototype property. I realize there are no classes in JS, that code therefore lives in objects instead of class definitions, and that "inheritance" must be achieved prototypically and not classically. That said, on with the code. Say I...
3
3584
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: Ajax.Base = function() {}; Ajax.Base.prototype = { setOptions: function(options) { <...>
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.