- Handwritten look deep copy
- The difference between == and ===
- Write a method to extract what search parameters inside
- I do not know about the write element width and height of the vertical and horizontal centering method
- The difference between 301 and 302
- git commands
- JS basic data types
- Css priority selector
- Element, the difference block elements inline
- What css pseudo-element
1. handwritten look deep copy
-
Shallow copy: just copy a reference to the address of the image, two objects point to the same address, in which a change, another change too.
-
Deep copy: refers to a change in a property of the object, another object does not change
Implement deep copy:
- Create a new object, cycle recursive deep copy
Click determine a reference type is an array or object method
function deepClone(obj){
let newObj;
// 先判断数据类型
if(obj.constructor === Array) { // 数组
newObj = [];
for(const item of obj) {
newObj.push(item);
}
} else if(obj.constructor === Object) { // 对象
newObj = {};
for(let key in obj){
newObj[key] = deepClone(obj[key]);
}
} else {
return obj;
}
return newObj;
}
- Using the
JSON.parse(JSON.stringify(obj))
method of implementation of deep copy
function deepClone(obj){
return JSON.parse(JSON.stringify(obj));
}
2. The difference between == and ===
- == comparison process
- If the two values of the same data type, and then compare the values, the same returns
true
, returns differentfalse
- If the two values of different data types, data type conversion, conversion rules are as follows:
(1) If one is null
, one is undefined
, they are equal
(2) If a value is a string, then the string into a numerical comparison
null == undefined; // true
'1' == 1; // true
'true' == true; // false
- === comparison process
- If they are different from the data type returned directly
false
使用 === 返回true时,说明比较的两个数据不仅类型相同,而且值也相等
使用 == 返回true时,二者数据类型不一定相同,但是转换为相同类型后的值一定相等
⚠️ NaN不等于任何值,包括本身
3. search inside the parameters of a method of extracting write about
?id=1&num=123
Regular Expressions Gets the specified parameters
function getUrlParam(name, search){
let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
let r = search.substr(1).match(reg);
if (r!=null) {
return unescape(r[2]);
}
return null;
}
getUrlParam('num', '?id=1&num=123'); // 123
4. Write not know about the width and height of vertical and horizontal centering element method
-
display:table-cell
Combinationdisplay:table-cell
andvertical-align、text-align
the horizontal and vertical elements in all rows in the middle of the parent element (internaldiv
settingsdisplay:inline-block
can). -
transform:translate(-50%,-50%)
-
Elastic layout
display:flex;
justify-content:center;
align-items:center;
The difference between 5.301 and 302
- 301 is a permanent redirect. Indicate the requested resource has been moved permanently to a new URI, and returns the new URI, and the browser will be automatically directed to the new URI, any future new request, you should use the new URI
- Temporary move. And 301 similar, temporary resources are moved, continue to use the original URI
Click for more http status codes
6. git commands (Click to view)
7. JS basic data types
String
Number
Boolean
null
undefined
Priority 8.css selector
css priority level sorting:! important> inline style> ID selector> class selector> tag> wildcard> inherited> Browser default property
9. The inner element row, the difference between block-level elements
-
Block elements will be on a separate line, the width of its parent element within the automatic fill line width of a line element is not exclusive, the adjacent row element will be arranged in the same row, the row line know less than, the line will change, with the width of the content element change
-
In general, the block elements may be provided
width,height
attributes, the element is provided inlinewidth, height
void (⚠️: block elements are provided, even if the width remains the exclusive line) -
Block elements may be provided
margin
andpadding
the horizontal direction in the row of elementspadding-left,padding-right,margin-left,margin-right
have the effect of generating margins, but the vertical directionpadding-top,padding-bottom,margin-top,margin-bottom
will not produce the effect of the margins. (Horizontal active, inactive, vertical direction)
10. css pseudo-element which
a:link {color: #FF0000} /* 未访问的链接 */
a:visited {color: #00FF00} /* 已访问的链接 */
a:hover {color: #FF00FF} /* 鼠标移动到链接上 */
a:active {color: #0000FF} /* 选定的链接 */
:active
Add style to an activated element.:focus
Add style to the element that has the keyboard input focus.:hover
When the mouse was suspended in the above elements, adding elements to the style.:link
Add style to unvisited links.:visited
Add style to the link has been visited.:first-child
Add style to the first child element.:lang
Add style to the element with the specified lang attribute.:first-letter
Add special style to the first letter of the text.:first-line
Add special style to the first line of text.:before
Before adding content elements.:after
Add content after the element.