-4

For example, i want to know how the querySelector method was built. I checked on MDN but there's only examples that show how to use it.

I also tried to check in the console.log but nothing readable.

mohiris
  • 55
  • 6

1 Answers1

0

There is a non-standard method to do this. Please be aware that it is not fully cross-browser compatible and shouldn't be used in a production environment.

function hello(){
    return "Hi!";
}
console.log(hello.toSource());

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toSource for more.

Edit: To see the source code of a built-in function, you will need to look at the engine source. This varies browser to browser. For example, Chrome uses the V8 engine. See https://github.com/v8/v8

Pal Kerecsenyi
  • 560
  • 4
  • 18