Forum Discussion
fahlen
15 years agoOccasional Contributor
I believe I have finally narrowed it down, and it appears the answer to my problem lies in your first comment about code in different units. I have included an example below to illustrate this. My extension of Array with a new method, and the usage of this method, are both located in Unit1. If I create the array in Unit1 and use the method "contains", then everything is OK. On the other hand, if I create the array in Unit2, as below, then I get an exception.
An array created in Unit2 is an array not extended with the method "contains". But since this worked before, I'm thinking maybe there has been a change in how arrays are handled when "passed between units". Is there any way I can recreate/clone the array created in Unit2 in Unit1, and this way have it be an array with the method "contains". Or do I have to include "Array.prototype.contains = ..." in Unit2 as well?
-- Unit1 --
-----------
//USEUNIT Unit2
Array.prototype.contains = function(element)
{
for (var i=0; i<this["length"]; i++)
{
if (this == element)
{
return true;
}
}
return false;
};
function Main()
{
try
{
var myArray = CreateArray();
myArray["contains"](2);
}
catch(exception)
{
Log["Error"]("Exception", exception["description"]);
}
}
-- Unit2 --
-----------
function CreateArray()
{
var a = new Array();
a["push"](1);
a["push"](2);
a["push"](3);
return a;
}
An array created in Unit2 is an array not extended with the method "contains". But since this worked before, I'm thinking maybe there has been a change in how arrays are handled when "passed between units". Is there any way I can recreate/clone the array created in Unit2 in Unit1, and this way have it be an array with the method "contains". Or do I have to include "Array.prototype.contains = ..." in Unit2 as well?
-- Unit1 --
-----------
//USEUNIT Unit2
Array.prototype.contains = function(element)
{
for (var i=0; i<this["length"]; i++)
{
if (this == element)
{
return true;
}
}
return false;
};
function Main()
{
try
{
var myArray = CreateArray();
myArray["contains"](2);
}
catch(exception)
{
Log["Error"]("Exception", exception["description"]);
}
}
-- Unit2 --
-----------
function CreateArray()
{
var a = new Array();
a["push"](1);
a["push"](2);
a["push"](3);
return a;
}
Related Content
- 4 years ago
- 12 years ago
- 6 years ago
- 3 years ago
Recent Discussions
- 17 hours ago
- 19 hours ago