473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assign prototype to event

Hello,

I am wondering why the following works, on IE6, but with an error : "Not
implemented".

function TEST(){}
TEST.prototype. Initialize = function()
{
var mImage = new Image();
var mDate = new Date();
var start = mDate.getTime() ;
mImage.onload = this.Alerting(s tart);//WORKS with ERROR "Not implemented"
//mImage.onload = function(){this .Alerting(start );}//ERROR "Object doesn't
support this property or method"
mImage.src = "winxp.gif" ;
}
TEST.prototype. Alerting = function(i_stri ng){alert(i_str ing);}
var mTest = new TEST();
mTest.Initializ e();

Can anybody guess why?
Thanks for your time.
Mar 12 '07 #1
11 1777
mImage.onload = this.Alerting(s tart);//WORKS with ERROR "Not implemented"

this syntax is incorrect for what you're trying to do. you want
mImage.onload to be set to a function- you're setting it to whatever
is returned from that function call.
create an anonymous function that calls "Alerting(. .)"

var _this = this; //important otherwise you will lose reference to
this TEST instance in the anonymous function and "this" will refer to
the image object (i think).

mImage.onload = function(start) {_this.Alerting (start);}

Mar 12 '07 #2
webgour wrote:
I am wondering why the following works, on IE6, but with
an error : "Not implemented".
One of the reasons that the declaration "don't work" is not greeted with
praise when presented here, and nobody is too impressed with the
declaration "it works" is people who say things like "works, on IE6, but
with an error".
function TEST(){}
TEST.prototype. Initialize = function()
{
var mImage = new Image();
var mDate = new Date();
var start = mDate.getTime() ;
mImage.onload = this.Alerting(s tart);//WORKS with ERROR "Not
implemented"
The - Alerting - method of this object does not have a return statement
and so returns the undefined value by default. IE is objecting to the
idea of assigning an undefined value to an intrinsic event handler. Which
is not too unreasonable as it allows the assigning of a null value when a
handler is to be cleared and otherwise it makes no sense to attempt to
assign anything but a reference to a function to the - onload - property.
//mImage.onload = function(){this .Alerting(start );}//ERROR
"Object doesn't support this property or method"
In the context of an intrinsic event handling method triggered in
response to an event the - this - keyword will (or, will with DOM named
and usually will with Image objects) refer to the object to which the
function has been assigned, the Image object in this case. The Image
object has no Alerting method so IE tells you it does not support the
method called.
mImage.src = "winxp.gif" ;
}
TEST.prototype. Alerting = function(i_stri ng){alert(i_str ing);}
var mTest = new TEST();
mTest.Initializ e();

Can anybody guess why?
<snip>

You want a guess as well? How about on of VK's: "an OS-specific gc
failure with
references in window.frames collection".

Richard.

Mar 12 '07 #3
Tom
On Mar 12, 4:18 pm, "Richard Cornford" <Rich...@litote s.demon.co.uk>
wrote:
webgour wrote:
I am wondering why the following works, on IE6, but with
an error : "Not implemented".

One of the reasons that the declaration "don't work" is not greeted with
praise when presented here, and nobody is too impressed with the
declaration "it works" is people who say things like "works, on IE6, but
with an error".
function TEST(){}
TEST.prototype. Initialize = function()
{
var mImage = new Image();
var mDate = new Date();
var start = mDate.getTime() ;
mImage.onload = this.Alerting(s tart);//WORKS with ERROR "Not
implemented"

The - Alerting - method of this object does not have a return statement
and so returns the undefined value by default. IE is objecting to the
idea of assigning an undefined value to an intrinsic event handler. Which
is not too unreasonable as it allows the assigning of a null value when a
handler is to be cleared and otherwise it makes no sense to attempt to
assign anything but a reference to a function to the - onload - property.
//mImage.onload = function(){this .Alerting(start );}//ERROR
"Object doesn't support this property or method"

In the context of an intrinsic event handling method triggered in
response to an event the - this - keyword will (or, will with DOM named
and usually will with Image objects) refer to the object to which the
function has been assigned, the Image object in this case. The Image
object has no Alerting method so IE tells you it does not support the
method called.
mImage.src = "winxp.gif" ;
}
TEST.prototype. Alerting = function(i_stri ng){alert(i_str ing);}
var mTest = new TEST();
mTest.Initializ e();
Can anybody guess why?

<snip>

You want a guess as well? How about on of VK's: "an OS-specific gc
failure with
references in window.frames collection".

Richard.
I'd be real careful when assigning custom event handlers to predefined
objects in javascript. Different browsers handle that kind of
assignment very differently. Consider:

function TEST {
var mImage = new Image() ;
mImage.onload = TEST.prototype. something;
mImage.src = "whatever" ;
}
TEST.prototype. something = function() {
alert(this) ;
}

You'd expect every browser to alert "object Image" or "[object Image]"
or some variation on that, but in Safari you'll find that it returns
"object Window".

Had a similar problem a month ago:
http://groups.google.com/group/comp....rosera&rnum=1#

Mar 13 '07 #4
Tom wrote:
On Mar 12, 4:18 pm, Richard Cornford wrote:
<snip>
>In the context of an intrinsic event handling method triggered in
response to an event the - this - keyword will (or, will with DOM
named and usually will with Image objects) refer to the object to
^^^^^
That was a typeo for 'node'.
>which the function has been assigned, the Image object in this
case.
<snip>
I'd be real careful when assigning custom event handlers to
predefined objects in javascript.
Would you? How are you defining a "predefined object" here?
Different browsers handle that kind of
assignment very differently. Consider:

function TEST {
var mImage = new Image() ;
mImage.onload = TEST.prototype. something;
mImage.src = "whatever" ;
}
TEST.prototype. something = function() {
alert(this) ;
}

You'd expect every browser to alert "object Image" or
"[object Image]" or some variation on that,
<snip>

Would I? I don't think I would expect the Image object in IceBrowser 5 to
ever execute the assigned function (or request the image).

Richard.

Mar 13 '07 #5
"Richard Cornford" <Ri*****@litote s.demon.co.ukwr ote in message
news:et******** ***********@new s.demon.co.uk.. .
Would I? I don't think I would expect the Image object in IceBrowser 5 to ever execute
the assigned function (or request the image).
You have been talking about IceBrowser for years. I am guessing you are a developer?

-Lost
Mar 13 '07 #6
-Lost wrote:
Richard Cornford wrote:
>Would I? I don't think I would expect the Image object in
IceBrowser 5 to ever execute the assigned function (or
request the image).

You have been talking about IceBrowser for years.
Why not, as it is a fully dynamic, scriptable, W3C DOM standard web
browser?
I am guessing you are a developer?
I am, but if you are implying that I had anything to do with the writing
of IceBrowser you would be mistaken.

Richard.

Mar 14 '07 #7
"Richard Cornford" <Ri*****@litote s.demon.co.ukwr ote in message
news:et******** ***********@new s.demon.co.uk.. .
-Lost wrote:
>Richard Cornford wrote:
>>Would I? I don't think I would expect the Image object in
IceBrowser 5 to ever execute the assigned function (or
request the image).

You have been talking about IceBrowser for years.

Why not, as it is a fully dynamic, scriptable, W3C DOM standard web browser?
Indeed. Duly noted.
>I am guessing you are a developer?

I am, but if you are implying that I had anything to do with the writing of IceBrowser
you would be mistaken.
Aye, that I was. My mistake.

Might I inquire as to what you are developing in JavaScript nowadays? I read your
previous articles (granted, I sorely need to reread them).

-Lost
Mar 15 '07 #8
-Lost wrote:
Richard Cornford wrote:
>-Lost wrote:
<snip>
>>I am guessing you are a developer?

I am, but if you are implying that I had anything to do with
the writing of IceBrowser you would be mistaken.

Aye, that I was. My mistake.

Might I inquire as to what you are developing in JavaScript nowadays?
I read your previous articles (granted, I sorely need to reread them).
I am writing the client-side framework and UI for a large-scale web
application, and probably will be for some time to come (details beyond
those would be subject to a confidentiality agreement).

Richard.

Mar 15 '07 #9
"Richard Cornford" <Ri*****@litote s.demon.co.ukwr ote in message
news:et******** ***********@new s.demon.co.uk.. .
-Lost wrote:
>Richard Cornford wrote:
>>-Lost wrote:
<snip>
>>>I am guessing you are a developer?

I am, but if you are implying that I had anything to do with
the writing of IceBrowser you would be mistaken.

Aye, that I was. My mistake.

Might I inquire as to what you are developing in JavaScript nowadays?
I read your previous articles (granted, I sorely need to reread them).

I am writing the client-side framework and UI for a large-scale web application, and
probably will be for some time to come (details beyond those would be subject to a
confidentiality agreement).
Heh, fair enough. I was prying for ideas to be honest.

I cannot think of any "large-scale" applications by which to test my limited skills. I
would love to tinker with something bordering on several hundred lines as opposed to
barely a hundred.

-Lost
Mar 16 '07 #10

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

Similar topics

8
3756
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:
16
25416
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?
10
4740
by: Robert | last post by:
Hi, I would like to determine if a property is available in an Event prototype. I tried doing this using: if (Event.prototype.srcElement) but I got an "Illegal operation on WrappedNative prototype object" exception. Is there anyway to see if it already has been defined.
12
2199
by: petermichaux | last post by:
Hi, I've been reading the recent posts and older archives of comp.lang.javascript and am surprised by the sentiments expressed about the prototype.js library for a few reasons: 1) The library has been referred to as "junk" many times which is a strong opinion against the relatively high popularity of the library. I know popularity doesn't make something good.
4
2093
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous' Effects to set Opacity to 1 for the active div and 0.5 for the inactive ones). Using prototype's event handling, I can see two ways to get this done:
4
10376
by: danf | last post by:
Can anyone tell me what the difference is between these two protoype methods? They are extensions of Javascript's Function class. Is bindAsEventListener just used to be compatible with IE's Event model? I'm thinking the only difference between the 2 methods is that bindAsEventListener passes the event into the function. I want to know how I can practically apply these.
1
2532
by: tdan | last post by:
I do not know how to get Event.stopObserving() to work in the context I am using it. I am displaying a Color Selection Table and attaching 2 events: 1. onmouseover to display the color to the user 2. onmouseup to select the color and hide the Table The onmouseup event should also call Event.stopObserving() so that mouse clicks are no longer being observed. An alert is shown when the mouse is clicked indicating the event handler is...
6
2627
by: TriFuFoos | last post by:
Hi there, I was wondering if anyone knew if/how to assign an event to a global variable? I tried to do it and IE 7 came back with an error saying "Member not found" My code looked similar to the following: var globalEvevnt; function showPopup(event){ globalEvent = event;
5
8082
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
8867
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
9386
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...
1
9158
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
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
5996
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
4503
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
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
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
2148
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.