Robert Rocha Robert Rocha - 24 days ago 17
Javascript Question

What does .equals() do?

I saw the use of an

.equals()
method in a Stackoverflow posting:

Any way to make jQuery.inArray() case insensitive?

var matchString = "MATCHME";
var rslt = null;
$.each(['foo', 'bar', 'matchme'], function(index, value) {
if (rslt == null && value.toLowerCase().equals(matchString.toLowerCase())) {
rslt = index;
return false;
}
});


Yet I cannot find any documentation on this method. Any references would help.

Answer

The code that you've seen in that other answer is not standard JS code.

It must have been lifted from a page that includes other code that adds the .equals() method to the String class (e.g. the "Processing.js" library) with code such as:

String.prototype.equals = function(that) {
    return this === that;
}

I've corrected the original answer so that it no longer has that dependency.

Comments