javascript basic knowledge accumulation 1

1. Definition of function parameters in javaScript
a. The parameter name can be repeated, but the value obtained through this parameter name is the last one of the actual passed parameter value,
such as function getA(a ,a ,b ,b){} if here If this variable is called in the method, the values ​​of a and b are the second ones of the actual passed parameters, which will be overwritten.
If the number of actual passed parameter values ​​is less than the number of parameters with the same name, the value obtained through this parameter name is undefined
For example, function getA(a ,b ,c ,d){} If the calling function is getA(a ,b) , then this variable is called in this method, then c ,d is undefined

b. Even if the function declares parameters, calling You can also not pass parameter values ​​when you want to.
This is often encountered in work. Unlike java, its function parameters can be passed arbitrarily

. c. When calling a function, you can pass several parameter values ​​to the function, regardless of the number of parameters when the function is declared. parameters, and the actual passed parameter values ​​can also be obtained in the function. I don't have the same situation in
this case. Can the multi-passed parameters be obtained in the function in this way? There are no variables?

The above characteristics are because when the function is called again, an arguments object will be created, which is responsible for managing parameters and some other properties, including getting all actual parameter values

​​2. Internal functions, anonymous functions
Since functions are a data type, Then it can also be assigned to a variable. Another way to create a function is as follows:
//Create an anonymous function
var func = function() {
  alert('func');
}
Calling this function is
func();

//return the value of the function type
var func = function() {
  return function() {
   alert('this is an internal anonymous function');
  }
}
func()(); //the first time of the two calls is to return a function, call it again to return the value of this function, the first time I didn't understand this usage, and then I read it several times.

//There is also a special function
(function() {alert('Run directly after creation' )})();

3. There are two references to the same object instance in the code, so the two references must be released before the garbage collector thinks that the object is no longer called
4. Definition of the host object: Flash implements animation For the production of , then Flash is the host, and for JS in the browser, the browser is the
host . The object that is implemented without depending on the host is regarded as a local object.

5. arguments object
a. caller
var a = new Function("alert ('a:'+a.caller)");
function b(){
  a();
  alert('b:' + b.caller);
}
b();

The director from the first call to alert above is the content of function b
and second time is empty
The caller attribute is not of the arguments object, but of the function itself. It shows the caller of the function. If the function is called in the global execution environment, he knows that it is null. If it is
called , his The value is that function.


6. Only one comment format is supported in css as follows
/* */

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608629&siteId=291194637