javascript - What is really happening when I call a function? -
this might simple question i've been thinking lately. i've tried researching answer have yet find satisfactory one.
basically, what's happening behind scene when call function? say:-
function sayhello(){ console.log('hello'); } sayhello(); //what's happening here?
i know doing sayhello.call();
or sayhello.apply();
same thing doing sayhello();
there more information on what's happening underneath or behind mysterious native code?
here of things interpreter make js function call:
- a new scope object created. arguments object created , put scope object arguments passed function in it.
- any local variables in new function put scope object.
- a reference next line of code pushed onto execution stack (so interpreter knows go when function returns).
- the pointer set appropriate.
- execution transferred code of function.
this managed internals of js interpreter (one of many jobs) native code.
if want call function b()
anytime function a()
called, can replace function a()
own proxy calls function b()
, calls original a()
.
Comments
Post a Comment