JavaScript (2)

Automatically invoked if the expression is immediately followed by ().
The arguments.length property returns the number of arguments received by the function:
function hidden parameters (arguments) are the real values ​​passed to the function when the function is called.
JavaScript functions have a built-in object arguments object.
The arguments object contains an array of arguments to the function call.
Note that this is a reserved keyword, you cannot modify the value of this.
When the function is not called by its own object, the value of this becomes the global object.
Using the window object as a variable can easily cause the program to crash.
call() and apply() are predefined function methods. Two methods can be used to call functions, and the first parameter of both methods must be the object itself.

Private variables can use closures.
With the unique "chain scope" structure of the Javascript language, the child object will look up all the variables of the parent


object . Therefore, all variables of the parent object are visible to the child object, and vice versa.
In essence, a closure is a bridge that connects the inside of the function with the outside of the function. There are two
biggest uses, one is to read the variables inside the function mentioned above, and the other is to keep the values ​​of these variables in memory at all times. middle.
Points to note when using closures
1) Closures will cause all variables in the function to be stored in memory, which consumes a lot of memory, so closures cannot be abused, otherwise it will cause performance problems on web pages, and may cause memory leaks in IE . The solution is to delete all unused local variables before exiting the function.
2) The closure will change the value of the variable inside the parent function outside the parent function. So, if you use the parent function as an object (object), the closure as its public method (Public Method), and the internal variable as its private property (private value), then you must be careful not to Feel free to change the value of the variable inside the parent function.

DOM: (Document Object Model)
1. Through the HTML DOM, all elements of the JavaScript HTML document can be accessed.
2. The HTML DOM enables JavaScript to react to HTML events.
Find HTML elements by id Find HTML elements
by tag name
Find HTML elements by class name
document.getElementById(id).innerHTML=new HTML
document.getElementById(id).attribute=new value
document.getElementById(id).style.property= new style
document.getElementById(id).style.visibility='hidden'"
Note: <button id="myBtn">click here</button>
<script>
document.getElementById("myBtn").onclick=function() {displayDate()};
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
toUpperCase() convert lowercase letters to uppercase letters

***document.getElementById("myBtn").addEventListener(" click", displayDate);
element.addEventListener(event, function, useCapture);
The first parameter is the type of event (such as "click" or "mousedown").
The second parameter is the function to be called after the event is triggered.
The third parameter is a boolean describing whether the event is bubbling or catching. This parameter is optional.

There are two ways of event delivery: bubbling and capturing.
Event delivery defines the order in which element events fire.
In bubbling, the event of the inner element will be triggered first, then the outer element, and
in capture, the event of the outer element will be triggered first, and then the event of the inner element will be triggered
**** HTML DOM add new element , you must first create the element (the element node) and then append the element to an existing one.



















Guess you like

Origin blog.csdn.net/Decadent_2014/article/details/46912529