help on JScript built-in function please

Posted by Nozshand on Fri 26 Dec 2014 10:08 AM — 2 posts, 15,186 views.

#0
Hi

I have noticed that some of the JScript functions listed on MSDN website is not supported in mushclient.

for example Array.indexOf

var a = ['red', 'blue', 'green', 'blue'];
var myFirstIndex = Array.indexOf(a, "blue");

always return "Object doesn't support this property or method" error;

for...in loop also behaves weird, it does not return proper value from the array.

Just wondering if there is anyway to make those work in mushclient?
Amended on Fri 26 Dec 2014 10:09 AM by Nozshand
USA Global Moderator #1
From http://www.tutorialspoint.com/javascript/array_indexof.htm

Quote:

This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:


if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}



JScript is one of those "other implementations".