Home >Web Front-end >JS Tutorial >A glimpse of the leopard in javascript: a brief analysis of formal parameters and actual parameters_javascript skills

A glimpse of the leopard in javascript: a brief analysis of formal parameters and actual parameters_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:27970browse

Introduction:
I saw a question from someone else today:

Copy the code The code is as follows:

function fn(x){
x = 10;
arguments[0] = 20;
console.log(x,arguments[0])
}
fn()

I feel like I know very little about this and I might as well give it a try, so I analyze it specifically.
I originally wanted to analyze it from a language perspective, but unfortunately I don’t have enough skills, so I can only give it a rough try, so I call it a glimpse of the leopard, and I hope the experts can correct me.
I wrote this yesterday. I thought about it again while eating today. After much deliberation, I felt that some of the questions were still unreliable, so I tried to revise it again.
Every JS introductory book will mention that there is an Arguments object arguments inside the JS function, which is used to actually pass in the parameters of the function when the function is called. fn.length saves the length of the formal parameter.
These are slightly useful for analysis, but I want to get more information about the formal parameters. I don’t know if anyone has a better way. I have no solution for the time being.
So we can only simulate it.
Ignore the simulation for now and start from the actual problem:
Copy the code The code is as follows:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



< title>