Where can i find the code source of javascript functions? [duplicate] - javascript

This question already has answers here:
Where can I find javascript native functions source code? [duplicate]
(3 answers)
Closed 1 year ago.
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.

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

Related

Javascript's performance.now() and Nodejs [duplicate]

This question already has answers here:
window.performance.now() equivalent in nodejs?
(9 answers)
Closed 5 years ago.
I'm new to Nodejs and I'm confused about something when timing:
If Nodejs is Javascript, then why Javascript's performance.now() doesn't work on Nodejs and I'm forced to use console.time() or the like?
How can I know what other Javascript functions doesn't work on Node?
Thanks!
Update: Although this was correct at the time it was written, this answer is now obsolete and modern versions of Node do support performance.now()
First, we have to be very clear about what JavaScript does -- and does not include.
The definition for what JavaScript includes is the EMCA-262 guide. This is the only thing that JavaScript is required to have.
Everything else - from the DOM to the performance object are additions provided by the host environment.
Some -- many -- browsers have chosen to add performance.now() but that is NOT part of JavaScript -- just something that JavaScript can call.
nodeJS currently doesn't support it -- at least not out-of-the-box, but it looks like someone created a module that does give you that ability.
I've not tried it, just did a quick google for 'node performance.now` and this was the first hit: https://www.npmjs.com/package/performance-now

What is `function floor() { [native code] }` in console [duplicate]

This question already has answers here:
How can I read ‘native code’ JavaScript functions?
(3 answers)
Closed 6 years ago.
How can I see how native js functions are implemented in a browser?
I've tried Math.floor.toString() but it returns "function floor() { [native code] }" and I can't step into the function using debugger.
You can't do this from the console, because the functions are part of the compiled browser executable … or, rather, its JavaScript engine. It is native code.
You may be able to read the source code for that engine, though, depending on which browser you're using. For example, Chrome's v8 source is on GitHub.
Updated
It's a native function. I'm guessing you could download the source code for a browser, as that's where it's implemented
Firefox Source code for example

get current spec name and status in jasmine2 in protractor [duplicate]

This question already has answers here:
Jasmine2: get current spec name
(6 answers)
Closed 7 years ago.
I found jasmine.getEnv().currentSpec.description returns the name of the spec in the Jasmine1 version but doesn't work when switching to jasmine2 framework with protractor.
In my scenario I would like to capture screenshot for failure with spec name in after Each(). I am not sure how could I achieve this with jasmine2.
I know there is a package "protractor-html-screenshot-reporter" which can provide you the screenshot for failures. but I want to use the coding part here.
Hope you can help me to get a workaround for the same.
Thanks
If I'm reading correctly you want to have your spec name in your screenshot. If that's the case check the path builder section of the "protractor-html-screenshot-reporter" page on github.

What is the name of this function declaration syntax only working in JScript (IE)? [duplicate]

This question already has answers here:
What does ‘::’ (double colon) do in javascript for events?
(6 answers)
Double colons in function declaration in Javascript?
(1 answer)
Closed 9 years ago.
I recently came upon this code on the web :
function window::onload() {
alert('onload!');
}
This (strange) syntax is only working in Internet Explorer (IE 8 in my case) and I wasn't sure of how it was called so I could search for it.
I simply want to know if there is some documentation related to this type of functions and if so, how are they called ?
That is automatic event binding in JScript, similar to the Object_EventName naming convention in VBScript.
See: Scripting Events
Supposedly it has meen removed in later version of Internet Explorer, just as some other rarely used non-standard features.
MS-ES5EX ECMAScript extension for Event Handler Function Definitions
http://msdn.microsoft.com/en-us/library/ff955429.aspx

What is the difference between document.getElementById('mybox') and mybox? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
document.getElementById(“someId”) Vs. someId
For example I have an element with id="mybox" attribute, is there any difference between calling it with document.getElementById('mybox') and mybox directly, as I see both work same in most browsers? The jsfiddle shows live example http://jsfiddle.net/usmanhalalit/TmS3k/
If there is no difference then why document.getElementById('mybox') is so popular, is it a bad practice to call mybox directly?
Some browsers in some rendering modes will create a global variable for each element with an id.
It is non-standard, won't work everywhere and definitely can't be depended upon.
They don't "both work the same". IE introduced making element ids into global variables, other browsers copied it to some extent but don't fully support it. It's considered a very bad idea, just don't do it.
mybox.value does not work in most cases. I believe IE is the only browser (and only some versions of it) that would support it. In my Firefox browser, I get mybox not defined error message in the console.

Categories

Resources