You can use Object.defineProperty to hide a prototype property/method by setting it as non-enumerable.
So if you're the one defining compare, do it like :
Object.defineProperty(Array.prototype, 'compare', { value : compareFunction } );
Since configurable, enumerable, and writable are false by default, you'll have a readonly, non-configurable and non-enumerable property : it won't stand in the way of your comparisons.
If you're not the one defining compare, you have to hope it is still configurable (look with Object. getOwnPropertyDescriptor or just test the following code) :
Object.defineProperty(Array.prototype, 'compare', { value : Array.prototype.compare } );
In the same way, you can do a loop on all Array prototype to check if every of its own property is enumerable, and set it to non-enumerable if it is.
http://jsbin.com/zunahebo/2/edit?js,console
Object.defineProperty(Array.prototype, 'compare', { value : compareArray } );
function compareArray(other) {
if (!other || other.length != this.length) return false;
for (var i=0; i<this.length; i++) if (this[i] !== other[i]) return false;
return true;
}
var a1 = [1, 2, 3, 4];
var a2 = [1, 2, 3, 4];
var a3 = [1, 2, 5, 6];
var a4 = [1, 2];
console.log(' a1 == a2 : ' + a1.compare(a2));
console.log(' a1 == a3 : ' + a1.compare(a3));
console.log(' a1 == a4 : ' + a1.compare(a4));