Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
TypeError defining two Array.prototype

I am defining two prototypes for array and one prototype needs to call other like that:

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;
    };

When I run [1,2,3,4].rotate() i get an error

> TypeError: this.swap is not a function
>     at Array.rotate (/home/user/array.js:11:10)

I think it's impossible to use an user-defined prototype inside another, but I want to understand why, and if I'm wrong (it's possible), how can I use? Thanks!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!