473,586 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Property in prototype

Hi,

I would like to determine if a property is available in an Event prototype.
I tried doing this using:

if (Event.prototyp e.srcElement)

but I got an "Illegal operation on WrappedNative prototype object"
exception. Is there anyway to see if it already has been defined.

One other question I have is if the __defineGetter_ _ method is part of
some Javascript/ECMA Script version or if it is Mozilla proprietary.

Thanks!
Robert
Jul 23 '05 #1
10 4730


Robert wrote:
One other question I have is if the __defineGetter_ _ method is part of
some Javascript/ECMA Script version or if it is Mozilla proprietary.


__defineGetter_ _ is implemented in the Spidermonkey engine that
implements JavaScript 1.5. That engine is used in Mozilla. So one could
say that __defineGetter_ _ is part of JavaScript 1.5 depending of what is
considered to define that version.
__defineGetter_ _ is not part of any existing ECMAScript specification
version.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2


Robert wrote:

I would like to determine if a property is available in an Event prototype.
I tried doing this using:

if (Event.prototyp e.srcElement)

but I got an "Illegal operation on WrappedNative prototype object"
exception. Is there anyway to see if it already has been defined.


Is that Firefox 1.03? Then you are probably running into a messy bug, a
workaround is described here:

<http://developer-test.mozilla.or g/en/docs/Working_around_ the_Firefox_1.0 .3_DHTML_regres sion>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3
Martin Honnen wrote:


Robert wrote:

I would like to determine if a property is available in an Event
prototype.
I tried doing this using:

if (Event.prototyp e.srcElement)

but I got an "Illegal operation on WrappedNative prototype object"
exception. Is there anyway to see if it already has been defined.

Is that Firefox 1.03? Then you are probably running into a messy bug, a
workaround is described here:


No I use Firefox 1.04
Are you implying that Event.prototype .srcElement should work?
Jul 23 '05 #4


Robert wrote:
No I use Firefox 1.04
Are you implying that Event.prototype .srcElement should work?


I don't think it should give an error, of course natively srcElement is
not part of the Mozilla DOM so you would need to add your own script to
add that property.

What is the user agent string of Firefox 1.04, I have tested here with
Mozilla 1.7.7 (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7)
Gecko/20050414) and it does not give an error when accessing
Event.prototype .srcElement
but simply gives undefined.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5
Martin Honnen wrote:


Robert wrote:
No I use Firefox 1.04
Are you implying that Event.prototype .srcElement should work?

I don't think it should give an error, of course natively srcElement is
not part of the Mozilla DOM so you would need to add your own script to
add that property.


Yes of course. I was expecting it to return undefined.

What is the user agent string of Firefox 1.04, I have tested here with
Mozilla 1.7.7 (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7)
Gecko/20050414) and it does not give an error when accessing
Event.prototype .srcElement
but simply gives undefined.


Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
Firefox/1.0.4

It seems mine is newer... So probably a regression. I will try to see if
they have a newer version available where they have fixed it again.
Jul 23 '05 #6


Robert wrote:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
Firefox/1.0.4

It seems mine is newer... So probably a regression. I will try to see if
they have a newer version available where they have fixed it again.


That is odd, I have now tried with Mozilla 1.7.8
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
and do not get any error either.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #7
Martin Honnen wrote:


Robert wrote:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8)
Gecko/20050511 Firefox/1.0.4

It seems mine is newer... So probably a regression. I will try to see
if they have a newer version available where they have fixed it again.

That is odd, I have now tried with Mozilla 1.7.8
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
and do not get any error either.


A restart has solved the problem.
Maybe the weather was too warm for the computer today :p
Anyway it works now :)
srcElement property being added if it was not already defined.

Thanks for trying to help me!
Jul 23 '05 #8
Robert wrote:
Martin Honnen wrote:


Robert wrote:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8)
Gecko/20050511 Firefox/1.0.4

It seems mine is newer... So probably a regression. I will try to see
if they have a newer version available where they have fixed it again.


That is odd, I have now tried with Mozilla 1.7.8
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511
and do not get any error either.

A restart has solved the problem.


I spoke too soon!
The problem only occurs after I have defined the srcElement.

So if I have executed the following code:

Event.prototype .__defineGetter __("srcElement" , function()
{
var node = this.target;
while (node.nodeType != 1)
node = node.parentNode ;
return node;
});

And later I do

if (Event.prototyp e.srcElement)

I will get the exception :(
Jul 23 '05 #9
Robert wrote:

Hi,
The problem only occurs after I have defined the srcElement.

So if I have executed the following code:

Event.prototype .__defineGetter __("srcElement" , function()
{
var node = this.target;
while (node.nodeType != 1)
node = node.parentNode ;
return node;
});

And later I do

if (Event.prototyp e.srcElement)

I will get the exception :(

That's quite normal, you've actually just defined a getter for
Event.prototype , and then you *call* it in the "if" structure while you
should just check its existence; as a result, in the call, "this" refers
to the prototype itself, not any event, and calling the getter defined
for "target" in such a context makes it fail.

Be more defensive, with the srcElement getter

Event.prototype .__defineGetter __(
"srcElement ",
function() {
var node=null;
if(this.constru ctor==Event) {
node = this.target;
while (node && node.nodeType != 1)
node = node.parentNode ;
}
return node;
}
);

and with the way you infer the existence of a property

function isUndefined(obj , prop){
var isUndefined=tru e;
if(obj.__lookup Getter__){
if(typeof obj.__lookupGet ter__(prop)!="u ndefined") {
isUndefined=fal se;
}
}
if(isUndefined) {
isUndefined=(ty peof obj[prop]=="undefined" );
}
return isUndefined;
}
HTH,
Yep.

Jul 23 '05 #10

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

Similar topics

3
11823
by: jonjon | last post by:
Hi, Is there any way of adding a property to an HTML element ? I heard about the "prototype" method but it doesn't work for HTML elements such as Images, or Paragraphs... Netscape implements HTMLElement objects but it seems to me that no equivalent exists in Internet Explorer ?? (I hate that browser :) Any idea ? Thank you, John.
16
25401
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
16
4316
by: Howard Jess | last post by:
All -- I'm trying to solve a problem for which I think the solution will be to *cheat*; but I don't mind doing so for this case. The background is: Given an object constructor, and an instance SampleObj = function() { this.prop = 1; }
15
1890
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following two? (1)
14
2015
by: emailscotta | last post by:
Some of the object properties in the Dojo Toolkit are set to objects but they are using syntax like this: object.property = new function() { this.property = someValue; this.property = someFunction; } Is the property set to a new object and if so what is the "new function()" statment doing?
13
2407
by: Sam Kong | last post by:
Hi, I am familiar with the ruby language. To use my ruby knowledge when writing in JavaScript, I use the following library. http://www.advogato.org/proj/Ruby.js/ If I include the file in my html, I can use ruby style methods in JavaScript.
1
1239
by: Peter Michaux | last post by:
Hi, What happens if you do this? function Person() {} Person.prototype = 7; var ted = new Person(); Also what happens if you set Person.prototype to an array or function?
4
2178
by: Spam Catcher | last post by:
When declaring class properties, what's the difference between: function EventBroker() { this.Register = function(eventName, handler) { } //AND
3
2644
by: szimek | last post by:
Hi! Like many others before recently I've found out that firstChild works little bit differently in IE and other browsers. I've got huge app that is currently IE only and used firstChild all over the place. Currently I wrote my own function firstNonTextChild(element), but it would be much more convenient for me to modify element.firstChild...
0
7839
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...
0
8202
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. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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

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.