473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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(start);//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_string){alert(i_string);}
var mTest = new TEST();
mTest.Initialize();

Can anybody guess why?
Thanks for your time.
Mar 12 '07 #1
11 1743
mImage.onload = this.Alerting(start);//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(start);//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_string){alert(i_string);}
var mTest = new TEST();
mTest.Initialize();

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...@litotes.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(start);//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_string){alert(i_string);}
var mTest = new TEST();
mTest.Initialize();
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*****@litotes.demon.co.ukwrote in message
news:et*******************@news.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*****@litotes.demon.co.ukwrote in message
news:et*******************@news.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*****@litotes.demon.co.ukwrote in message
news:et*******************@news.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
-Lost wrote:
Richard Cornford wrote:
>-Lost wrote:
<snip>
>>Might I inquire as to what you are developing in
JavaScript nowadays?
<snip>
>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.
We may have very different concepts of what "large-scale" is. I am
working with a client-side code base of 70,000 odd lines (with at least
60 times the server-side code), and you would not want to even attempt
that on your own or without being paid for it.
I would love to tinker with something bordering on several hundred
lines as opposed to barely a hundred.
One thing to remember is that your firsts attempts at anything will
likely be unsatisfactory. Once you have a handle on the langue and the
object model provided by the host the next things to learn are the
considerations that apply to the design, and you don't learn those
without trying and seeing where you fall short.

You could pick on anything, whether it has been done before (or done to
death) you can still try to do it better, or do it in your style. Even
the silly gimmicky things (that nasty 'falling snow' script, for example)
can be better done, and much learnt along the way.

Probably the most important thing is to expose your creations to
criticism, and then address those criticisms with practical changes.

Richard.

Mar 17 '07 #11
"Richard Cornford" wrote in message news:et*******************@news.demon.co.uk...
-Lost wrote:
>Richard Cornford wrote:
>>-Lost wrote:
<snip>
>>>Might I inquire as to what you are developing in
JavaScript nowadays?
<snip>
>>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.

We may have very different concepts of what "large-scale" is. I am working with a
client-side code base of 70,000 odd lines (with at least 60 times the server-side code),
and you would not want to even attempt that on your own or without being paid for it.
Yet again, you are indeed correct. I could not even possibly imagine 70,000 lines of
JavaScript. I get queasy looking over a few hundred lines.
>I would love to tinker with something bordering on several hundred
lines as opposed to barely a hundred.

One thing to remember is that your firsts attempts at anything will likely be
unsatisfactory. Once you have a handle on the langue and the object model provided by
the host the next things to learn are the considerations that apply to the design, and
you don't learn those without trying and seeing where you fall short.

You could pick on anything, whether it has been done before (or done to death) you can
still try to do it better, or do it in your style. Even the silly gimmicky things (that
nasty 'falling snow' script, for example) can be better done, and much learnt along the
way.
Duly noted. I wrote one of those "falling" scripts in ActionScript many a month ago, and
have long thought about porting it to JavaScript. Of course, I was not about to brag
about it. : )

For example:

frame 1 {
Stage.showMenu = 'false';
Stage.scaleMode = 'noScale';
var snowflakes = 100;
var stagewidth = 600;
var stageheight = 200;
t = 0;
while (t != snowflakes) {
mc = _root.attachMovie('snowflake', 'snow' + t, t);
mc.dir = (30 + Math.random() * 30) * Math.PI / 180;
mc.speed = Math.random() * 8;
mc._yscale = 15 * mc.speed;
mc._xscale = mc._yscale;
mc._x = Math.random() * stagewidth;
mc._y = Math.random() * stageheight;
mc.onEnterFrame = function () {
var xspeed = Math.cos(this.dir) * this.speed;
var yspeed = Math.sin(this.dir) * this.speed;
this._x += xspeed;
this._y += yspeed;
if (this._x stagewidth) {
this._x = 0;
}
if (this._y stageheight) {
this._y = 0;
}
};

++t;
}
}
}

Sorry, to go OT with ActionScript, I just thought it wildly coincidental that you
mentioned a snowflake script.
Probably the most important thing is to expose your creations to criticism, and then
address those criticisms with practical changes.
Thank you for the wise advice. It is very much appreciated.

-Lost
Mar 17 '07 #12

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

Similar topics

8
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...
16
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...
10
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...
12
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...
4
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'...
4
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...
1
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...
6
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...
5
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.