I need to find out how exactly a function works, so where can i find the source code of function in Javascript ?
For example: arr.sort(function(a, b){return a-b});
this function sort() gonna sort all index of an array.
But i don't know how this function compare all the Index to each other specifically
-
1javascript-array-sort-implementationMara Black– Mara Black2021年12月16日 20:45:32 +00:00Commented Dec 16, 2021 at 20:45
-
It doesn't compare indices, it compares elements of the array. And why do you need to know that?UnholySheep– UnholySheep2021年12月16日 20:45:33 +00:00Commented Dec 16, 2021 at 20:45
-
Does this answer your question? Javascript Array.sort implementation?pilchard– pilchard2021年12月16日 20:48:31 +00:00Commented Dec 16, 2021 at 20:48
-
sort() is a method, that is not declared in a script but built-in in the browser within the javascript support module. In theory there is not only one source since it is implemented in the google chrome source, opera browser source etc. Indeed on all the browsers or Javascript interpreter just to include also node.js use case the function should be working at the same way so you could check the Mozilla related documentation here to find more about it developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…A. Lion– A. Lion2021年12月16日 20:56:15 +00:00Commented Dec 16, 2021 at 20:56
1 Answer 1
To direct answer the question you asked, you can find function source code like this:
console.log([].sort);
or
console.log(myFunc);
This works with any function.
answered Dec 16, 2021 at 20:50
Sign up to request clarification or add additional context in comments.
Comments
lang-js