1. "|" operator if | the first parameter of the operator is true, or a value that can be converted to trued, the operator returns its first parameter. Otherwise, the second parameter is returned. For example, a = A | []; if a has been defined and is not null, it returns a; otherwise, A is null.
2. Although there are fixed numbers of named parameters when defining JavaScript Functions, the number of parameters passed to this function can be arbitrary. The arguments object allows full access to the actual parameter values. The arguments object is an array-like object.
An example of arguments:
Function B (){
Alert ();
Arguments [0] = [12, 3];
Alert ();
}
B (); // undefined, undefined
B (1); // "1", "12, 3 ";
-------------------------
In this example, we can see that 1. The arguments object is allocated with memory only when parameters are passed in. 2. The arguments object has an extraordinary feature. When a function has a named parameter, the array element of the arguments object is a synonym for the local variables that store the function parameters.
3. callee attributes
The arguments object defines the callee attribute to reference the currently executed function. This attribute is not very useful, but it can be used to recursively call unnamed functions.
Function (x ){
If (x <= 1) return 1;
Return x * arguments. callee (x-1 );
}
4. Apply () and call () Methods: The apply () method has two parameters: this object and an array of parameters to be passed to the function. For example:
Function saycolor (sprefix, ssuffix) {alert (sprefix + this. color + ssuffix) ;}; var OBJ = new object (); obj. color = "blue"; saycolor. call (OBJ, new array ("the color is", "a very nice color indeed. "); // The Last generated message is still" the color is blue, a very nice color indeed."
The call () method is the most similar to the classic object impersonating method. Its first parameter is used as the object of this, and other parameters are directly passed to the function itself.
Example:
Function saycolor (sprefix, ssuffix) {alert (sprefix + this. color + ssuffix) ;}; var OBJ = new object (); obj. color = "blue"; saycolor. call (OBJ, "the color is", "a very nice color indeed. "); // The Last generated message" the color is blue, a very nice color indeed."