473,396 Members | 1,809 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,396 software developers and data experts.

Where is the property going?

I have made this objec because I'm trying to encapsulate the namespaces
so that it'll work for multiple images on one page and I'd like to be
able give this away to people. However when I run this the
this.fadeimages property get's lost I don't know why. here's the code

<html><head><title>EXample</title><script type="text/javascript">
function Fader() {
this.fadeimages=new Array()
}

Fader.prototype.getfadeimages=getfadeimages;
function getfadeimages() {
alert('getfadeimgaes');
return this.fadeimages;
}//end getfadeimges()
Fader.prototype.setfadeimages=setfadeimages;
function setfadeimages(arry) {
alert('setfadeimages');
this.fadeimages=arry;
}//end setfadeimgaes
Fader.prototype.go=go;
function go() {
alert('GO');alert(self.getfadeimages()[0][0]);
}

</script></head><body><script type="text/javascript">
var fader=new Fader();
imagelist=new Array();
imagelist[0]=["stock/table1.jpg", "", ""] //plain image syntax
imagelist[1]=["stock/cake1.jpg", "http://www.google.com", ""] //image
with link syntax
imagelist[2]=["stock/eggs1.jpg", "http://www.javascriptkit.com",
"_new"] //image with link and target syntax
fader.setfadeimages(imagelist);
alert('fadeimages[2][2] ' + fader.fadeimages[2][2]);
fader.go()
</script></body></html>

Jul 23 '05 #1
2 1139
Lee
fl*******@gmail.com said:

I have made this objec because I'm trying to encapsulate the namespaces
so that it'll work for multiple images on one page and I'd like to be
able give this away to people. However when I run this the
this.fadeimages property get's lost I don't know why. here's the code

<html><head><title>EXample</title><script type="text/javascript">
function Fader() {
this.fadeimages=new Array()
}

Fader.prototype.getfadeimages=getfadeimages;
function getfadeimages() {
alert('getfadeimgaes');
return this.fadeimages;
}//end getfadeimges()
Fader.prototype.setfadeimages=setfadeimages;
function setfadeimages(arry) {
alert('setfadeimages');
this.fadeimages=arry;
}//end setfadeimgaes
Fader.prototype.go=go;
function go() {
alert('GO');alert(self.getfadeimages()[0][0]);
}

</script></head><body><script type="text/javascript">
var fader=new Fader();
imagelist=new Array();
imagelist[0]=["stock/table1.jpg", "", ""] //plain image syntax
imagelist[1]=["stock/cake1.jpg", "http://www.google.com", ""] //image
with link syntax
imagelist[2]=["stock/eggs1.jpg", "http://www.javascriptkit.com",
"_new"] //image with link and target syntax
fader.setfadeimages(imagelist);
alert('fadeimages[2][2] ' + fader.fadeimages[2][2]);
fader.go()
</script></body></html>


You've got a couple of problems. The trivial one, correcting which
may make your code *appear* to work, is that your "go()" method
refers to self.getfadeimages() instead of this.getfadeimages().

The more serious problem is that you don't seem to realize what
happens when you assign one array reference to another.

this.fadeimages=arry

discards the reference to the empty array that your Fader()
constructor created and replaces it with a reference to the
array that you passed in as an argument. At this point, the
reference in your Fader object points to the global imagelist
array. None of the elements have been copied. If you now
make changes to imagelist, those changes will be reflected
when you invoke fader.go();

To copy an array, use one of the Array methods, such as:

this.fadeimages=arry.slice(0);

Jul 23 '05 #2
To copy an array, use one of the Array methods, such as:

this.fadeimages=arry.slice(0);

I've done what you have suggested. The self was somethign I have since
changed back and forgot to change back. I get the result I expect from
inside go but when I call getfadeimages from any other function it's
gone. and I've enumerated through the object properties and printed
them and none of my object properties are showing. It seems like
this.fadeimages disapears. If you think it would be helpful I'll post
the complete code that I have so far.

Jul 23 '05 #3

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

Similar topics

6
by: =?Utf-8?B?UGhpbGw=?= | last post by:
I am making the transition from VB to C# and am stumped on a seemingly simple task. I have created a class and defined a property using set/get. Now from one of my forms I want to set the...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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...

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.