different forms of JS functions

Y

Yan Huang

When I was looking at Narcissus (a JS interpreter written in JS,
shipped with Mozilla Firefox) code, I noticed that it puts all JS
functions into 3 categories, implied by this line of code:

const DECLARED_FORM = 0, EXPRESSED_FORM = 1, STATEMENT_FORM = 2;

For DECLARED_FORM and EXPRESSED_FORM, I can guess what they are and
verify my guess by running narcissus parser.

function f(){} ------ DECLARED_FORM
f = function(){} --------- EXPRESSED_FORM

Does anyone know what a STATEMENT_FORM JavaScript function could be?

Thanks,
Yan Huang
 
Y

Yan Huang

When I was looking at Narcissus (a JS interpreter written in JS,
shipped with Mozilla Firefox) code, I noticed that it puts all JS
functions into 3 categories, implied by this line of code:

const DECLARED_FORM = 0, EXPRESSED_FORM = 1, STATEMENT_FORM = 2;

For DECLARED_FORM and EXPRESSED_FORM, I can guess what they are and
verify my guess by running narcissus parser.

function f(){} ------ DECLARED_FORM
f = function(){} --------- EXPRESSED_FORM

Does anyone know what a STATEMENT_FORM JavaScript function could be?

Thanks,
Yan Huang

After a even closer examination of the code again, I found the
STATEMENT_FORM function corresponds to functions like,

if(b){
function f(){}
}

Then, I would guess the difference between STATEMENT_FORM functions
and non-STATEMENT_FORM ones are that, STATEMENT_FORM local functions
are not created at the time of the control flow enters a new execution
context, like the entrance of a function, whereas non-STATEMENT_FORM
local functions are created before the control flow starts executing
in the new execution context. In this case, all the preceding
statements executed before the STATEMENT_FORM function f can affect
the behavior of f (by modifying object values in f's scope chain). But
local statements have no effects on behaviors of non-STATEMENT_FORM
functions.

Is my intuition correct? Hope one can verify my guessing, or refute
it.

Thanks,
Yan Huang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top