Forum Discussion

fahlen's avatar
fahlen
Occasional Contributor
15 years ago

New behavior for JScript Object prototype property

When using TestComplete 7.20, I extended arrays, numbers and strings with new functionality as shown in the following.



Array.prototype.contains = function(element)

{

  for (var i=0; i<this["length"]; i++)

  {

    if (this == element)

    {

      return true;

    }

  }

  return false;

};



Number.prototype.toFixed = function(precision)

{

  var power = Math["pow"](10, precision || 0);

  return String(Math["round"](this * power) / power);

};



String.prototype.repeat = function(n)

{

  return new Array(n + 1)["join"](this);

};





This worked well. However, now that I'm using TestComplete 7.52, I keep getting exceptions stating:



Microsoft JScript runtime error

Object doesn't support this property or method



I use C#Script, but as I understand it, this uses an underlying JScript engine. My questions is this. Has any changes been made that would prevent me from extending arrays, numbers and strings with new methods? Will this be a no no, from now on? This worked fine before. It would be great if anyone could shed some light on the matter.

15 Replies