0

I'm learning JavaScript and am interested in reading the code that makes array.filter, array.sort, and the like work.

I'm not sure what the correct terminology for these methods are, but assumed Global / Built-in after reading this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects.

Is it possible to read the code that makes them work?

dwrz
  • 2,991
  • 2
  • 10
  • 14

2 Answers2

1

Short answer: No.

Long answer: It depends.

Of course these methods are written somewhere; but not usually in JavaScript. They're built into the interpretor, so they're generally written in C/C++, or some other low-level language, depending on which JavaScript engine you're using.

The Spidermonkey, used in FireFox, source is available here, or the V8 sources, used in Node.js and Chrome, here. The source for Microsoft's Chakra engine, used in Edge, is available here. There are many other JavaScript engine implementations, though, some open source, others not.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
1

There are two levels to the answer to this question. The first level is the specification, for example for array.prototype.filter, it is defined in ECMAScript 5.1 here.

Each JavaScript engine then writes their own implementations of these. Depending on which engine you're interested in, you will be able to see the actual code implementation. For example, V8 (in Chrome) is open source.

James Thorpe
  • 31,411
  • 5
  • 72
  • 93