1. Empty objects
```
var o = null;
An empty object, which is characterized only by the variable o no object data
```
# storage characteristics for value types and reference types
1. Memory logical Structure (drawing)
2. Assigning values
```
var num = 123;
var num2 = num;
```
* Value type assignment of the storage characteristics, the variables in the data are all copied one copy, stored to the new variable.
* ' var num = 123 ' indicates that the number stored in the variable is 123.
* A copy of the data is then copied, which is 123 copies of one copy. Then there are 2 arrays in memory
* Assign copy data to ' num2 '
* It is characterized by having * * Two copies of data in memory * *.
* Exercise: var o = {name: ' Zhang San '};, var obj = o;
3. Assignment of reference types
```
var o = {name: ' Zhang San '};
var obj = o;
```
* Assignment is to copy the data stored in the variable o and assign the data to obj
* 1 of data in memory
* Problem: The Name property modified with obj affects the name in O
# Deep copy with light copy
1. What is a deep copy and what is a shallow copy
* If a copy of all the reference structure of the data is copied, then the data is in memory independent of the deep copy
* If the copy is only for the properties of the current object copy, and the property is a reference type this is not considered, then the shallow copy
* Copy: Copy copies. Refers to copying object data.
* When discussing the deep copy and the shallow copy, make sure that the object's properties are also reference types.
2. Encapsulation of the Code
* Using object-oriented thinking, the object will usually have a copy of the method to complete their own copy
* If you need to encapsulate an object into a shallow copy
* This is inside a function (method) that represents the object that called the function (method).
# # Noon Question
1. The difference between the onload and the read in JQ
2. Type conversion (the only one in JS is not equal to his own is NaN)
# Dynamic properties of the object
1. In JS, a grid object needs attributes, and it can be added by using the object. Property name = value. As long as the assignment succeeds, the object adds properties.
2. Access form of object properties
* Dot syntax: ' o.name '
* Associative array: ' o[name] '
3. Ever used
```
function Mix (obj1, obj2) {
For (var k in obj2) {
obj1[K] = obj2[K];
}
}
```
4. When you need to add members dynamically to an object, you must use the syntax of the associative array
```
Use the syntax of an associative array, access its Name property, and call its SayHello method
var o = {
Name: ' Zhang San ',
Sayhello:function () {
Console.log (' Hello, my name ' + this.name);
}
};
Console.log (O.name);
Console.log (o[' name ');
O.sayhello ();
o[' SayHello '] ();
```
# as parameter parameters
1. As a function parameter, a copy of the parameter's data is passed to the parameter in the definition of the function.
```
function foo (num) {}
var a = 123;
Foo (a);
```
* function when calling, first need to copy the data in the parameter. That is, the number 123 copies one copy.
* Jump to the definition of the function (function body), once again completed the assignment of the parameter, that is, num = 123.
* Formal entry function, ready to execute each sentence in the function.
2. A value type is a feature that is passed as a function parameter, and the function is two different variables outside the function, only the value is equal.
3. A reference type is a feature passed as a function parameter, and within a function is two different variables outside the function, but points to the same object.
* Therefore allows modifying the data of objects outside the function inside the function
# function of the constructor
# # What is a constructor for?
1. Initialization of the data
2. To add attributes to the object in JS, initialize the attribute value with
# # Process for creating objects
1. Code: ' var p = new person (); '.
2. First, operator new creates an object. It is similar to ' {} ' and is an ' no member ' object.
* Use new to create an object whose type is the name of the constructor that created it.
* Use {} Anyway is object type, equivalent to ' new object '.
3. Then call the constructor to initialize the member
* constructor at the beginning of the call, there is an assignment operation, this = the object that was just created.
* Therefore in the constructor this represents the object that was just created.
4. Add members to the object using the object's dynamic properties in the constructor.
# # Jobs:
```
function person (name, age, gender) {
THIS.name = name;
This.age = age;
This.gender = gender;
}
var p = new Person (' Zhang San ', 19, ' Male ');
```
# exception
# # Exception Concept
An exception is an error that occurs during the execution of a program.
After the exception in JS, the browser will give an error code, is the error message. Error messages consist of error types and error messages
# # How to handle exceptions
is to be able to continue execution after an exception occurs. The most unusual feature of the exception is that once the code has an exception, the code is no longer executed.
Common exceptions are in two main categories:
1. Diversity of operating environments
2. Syntax error, code error
# # # Try-catch syntax
That is, try to do this if error trapping errors occur
```
...
try {
Code that may be wrong
} catch (e) {
Code to handle the error
}
...
```
1. The code is working properly, if there is an error in try, the code behind the wrong statement in the try is no longer executed and jumps directly into the catch
2. Handling error messages in Catch
3. Then proceed to the following code:
4. If no error occurs in the try, then execute the following code without taking the catch directly
# # How to throw an exception
```
Throw Object
```
1. Throw is the syntax for throwing exceptions, followed by an object, the error message object
2. Typically this object is created using ' new error ' (' Error message ') '. Arbitrary objects are also supported.
```
function ShowMessage (msg) {
To display a piece of text, so I make a limit
if (typeof msg!== ' string ') {
throw new Error (' the passed parameter is not a string ');
}
It's normal.
Console.log (msg);
}
```
# # Supplement
1. The final structure of the Try-catch syntax is try-catch-finally
```
try {
Code that may be wrong
} catch (e) {
Execute if an error occurs
} finally {
End Try this code block before execution, i.e. last execution
}
```
2. Level transfer
```
Function F1 () {
F2 ();//F1 called caller, or call function, F2 called called, or called function
}
function F2 () {
F3 ();
}
Function F3 () {
throw new error (' Error ');
}
F1 ();
```
# DOM Operations
# # Draw the DOM tree
```
<!doctype html>
<title> Testing </title>
<body>
<!--test-
<div>
Hello I'm a <span style= "color:red" >div</span> tags </div>
</body>
```
# # The conclusion of any DOM tree structure
1. What is the operation of the so-called DOM operation?
2. General DOM tree structure
```
Parent node
Brother Node
Current node
Attribute node
Child nodes
Brother Node
```
Object-oriented day02