Estoy definiendo dos prototipos para una matriz y un prototipo necesita llamar a otro así:
Array.prototype.swap = function (x, y) { var b = this[x]; this[x] = this[y]; this[y] = b; return this; }; Array.prototype.rotate = function () { for (idx in this) { nextIdx = idx + 1 < this.length ? idx + 1 : 0; this.swap(idx, nextIdx); } return this; }; Cuando ejecuto [1,2,3,4].rotate() un error
> TypeError: this.swap is not a function > at Array.rotate (/home/user/array.js:11:10)Creo que es imposible usar un prototipo definido por el usuario dentro de otro, pero quiero entender por qué, y si me equivoco (es posible), ¿cómo puedo usarlo? ¡Gracias!