&& function function operating mechanism

In js, the method is a function (a function thereof), it is generally based on a function in order to achieve a certain function

Function is to achieve the purpose of the birth of the package, to achieve a function code is encapsulated into a function, the latter wants to achieve the same functionality, as long as you can perform this function, without having to write code repeat again, played a "high coupling, low cohesion "role

High coupling, low cohesion: reducing redundant code, code reuse to improve

// syntax 
function function name (parameter) { 

     function body: js code functions implemented 

} 

function name (); // perform functions 

// for ES6 arrow function 

let the function name (variable name) = (parameter) => { 

   function body 
}
to function FUNCTION is fn, (), { 

   var num = of 10 ; 
   .... 

}, 


fewatal fn =, (), => { 

  fewatal num = of 10 ; 

}, 

Fn, (),;

Function as a reference to a data type, it is also operating in accordance with a reference address, followed by learning about the operation mechanism of the function:

Create a function:

1, will first open a new heap memory, the function of the code string member as stored in memory

2, the opening up of heap memory address assigned to the function name (variable name)

Execute functions:

Prior to heap memory to store code string becomes a real code execution, to achieve proper function

1, performs the function, will first form a private scope (stack memory, code execution environment)

2, copy the code strings stored in a heap before coming into real js code to execute in a top-down scope newly opened

And function parameter arguments

Parameter storage function is: When we function in a function in the package, found the raw material uncertainty, you need to perform a function when passed in, this time on the basis of the parameters of the mechanism, provide access to

For example: find any two numbers, parameters are any two numbers do not know

function SUM (n, m) { // two numbers formal parameters n and m represents an inlet and requirements of 

    return n + m; 
} 

SUM ( 10,30); // argument specific data value n is 10, m is 30 
SUM (50); // n-is 50, m is undefined
SUM (); // n-, m is undefined
SUM (l, 2,3); // n-is 1, m is 2, 3 does not receive the parameter variables

Parameter: the time entry function of creating, may have a plurality of

Arguments: time to perform the function of transmitting a specific data value

 

Guess you like

Origin www.cnblogs.com/xinxinxiangrong7/p/11431705.html