update
This commit is contained in:
parent
62c56cc64d
commit
0c410c9736
@ -280,44 +280,45 @@ console.log(Date.now()); // 打印结果举例:1589448165370
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<style>
|
||||
div {
|
||||
width: 800px;
|
||||
margin: 200px auto;
|
||||
color: red;
|
||||
text-align: center;
|
||||
font: 600 30px/30px "simsun";
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8" />
|
||||
<title></title>
|
||||
<style>
|
||||
div {
|
||||
width: 800px;
|
||||
margin: 200px auto;
|
||||
color: red;
|
||||
text-align: center;
|
||||
font: 600 30px/30px 'simsun';
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
|
||||
<script>
|
||||
//模拟日历
|
||||
//需求:每天打开这个页面都能定时显示年月日和星期几
|
||||
<script>
|
||||
//模拟日历
|
||||
//需求:每天打开这个页面都能定时显示年月日和星期几
|
||||
function getCurrentDate() {
|
||||
//1.创建一个当前日期的日期对象
|
||||
const date = new Date();
|
||||
//2.然后获取其中的年、月、日和星期
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth();
|
||||
const hao = date.getDate();
|
||||
const week = date.getDay();
|
||||
// console.log(year+" "+month+" "+hao+" "+week);
|
||||
//3.赋值给div
|
||||
const arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
|
||||
const div = document.getElementsByTagName('div')[0];
|
||||
return '今天是:' + year + '年' + (month + 1) + '月' + hao + '日 ' + arr[week];
|
||||
}
|
||||
|
||||
//1.创建一个当前日期的日期对象
|
||||
var date = new Date();
|
||||
//2.然后获取其中的年、月、日和星期
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth();
|
||||
var hao = date.getDate();
|
||||
var week = date.getDay();
|
||||
// console.log(year+" "+month+" "+hao+" "+week);
|
||||
//3.赋值给div
|
||||
var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
|
||||
var div = document.getElementsByTagName("div")[0];
|
||||
div.innerText = "今天是:"+year+"年"+(month+1)+"月"+hao+"日 "+arr[week];
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
const div = document.getElementsByTagName('div')[0];
|
||||
div.innerText = getCurrentDate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
```
|
||||
|
||||
实现效果:
|
||||
|
@ -1078,7 +1078,7 @@ console.log(JSON.stringify(numArr)); // 打印结果:[1, 2, 3]
|
||||
|
||||
上面这段代码,你可要看仔细了,打印结果是 `[1, 2, 3]`,不是 `[2, 4, 6]`。
|
||||
|
||||
**2、数组的元素是引用数据类型**:(直接修改整个对象时,无法改变原数组)
|
||||
**2、数组的元素是引用数据类型**:(直接修改整个元素对象时,无法改变原数组)
|
||||
|
||||
```js
|
||||
let objArr = [
|
||||
@ -1095,7 +1095,7 @@ objArr.forEach((item) => {
|
||||
console.log(JSON.stringify(objArr)); // 打印结果:[{"name":"千古壹号","age":20},{"name":"许嵩","age":30}]
|
||||
```
|
||||
|
||||
**3、数组的元素是引用数据类型**:(修改对象里的某个属性时,可以改变原数组)
|
||||
**3、数组的元素是引用数据类型**:(修改元素对象里的某个属性时,可以改变原数组)
|
||||
|
||||
```js
|
||||
let objArr = [
|
||||
@ -1148,6 +1148,10 @@ objArr2.forEach((item, index, arr) => {
|
||||
console.log(JSON.stringify(objArr2)); // 打印结果:[{"name":"小明","age":28},{"name":"小明","age":34}]
|
||||
```
|
||||
|
||||
**总结**:
|
||||
|
||||
如果纯粹只是遍历数组,那么,可以用 forEach() 方法。但是,如果你想在遍历数组的同时,去改变数组里的元素内容,那么,最好是用 map() 方法来做,不要用 forEach()方法,避免出现一些低级错误。
|
||||
|
||||
参考链接:
|
||||
|
||||
- [forEach 到底可以改变原数组吗?](https://juejin.im/post/5d526a4ae51d4557dc774e7d)
|
||||
|
@ -183,14 +183,14 @@ for ... of 的循环可以避免我们开拓内存空间,增加代码运行效
|
||||
`for ... of`既可以遍历数组,也可以遍历 Map 对象。
|
||||
|
||||
|
||||
## for in:遍历对象的属性名
|
||||
## for in:遍历对象的属性
|
||||
|
||||
> `for ... in`主要用于遍历对象,不建议用来遍历数组。
|
||||
|
||||
语法:
|
||||
|
||||
```javascript
|
||||
for (const 变量 in 对象名) {
|
||||
for (const 变量 in 对象) {
|
||||
|
||||
}
|
||||
```
|
||||
|
@ -55,10 +55,12 @@ obj2:{"name":"qianguyihao","age":28,"info":{"desc":"永不止步"}}
|
||||
**语法**:
|
||||
|
||||
```js
|
||||
newObj = Object.assgin(newObj, 被拷贝的对象);
|
||||
obj2 = Object.assgin(obj2, obj1);
|
||||
```
|
||||
|
||||
参数解释:`newObj`指的是**拷贝给谁**。
|
||||
**解释**:将`obj1` 拷贝给 `obj2`。
|
||||
|
||||
**作用**:将 obj1 的值追加到 obj2 中。如果对象里的属性名相同,会被覆盖。
|
||||
|
||||
**例 1**:
|
||||
|
||||
@ -115,6 +117,35 @@ const obj2 = {};
|
||||
const obj3 = Object.assign(obj2, obj1);
|
||||
```
|
||||
|
||||
**例4**:【重要】
|
||||
|
||||
```js
|
||||
const obj1 = {
|
||||
name: 'qianguyihao',
|
||||
age: 28,
|
||||
desc: 'hello world',
|
||||
};
|
||||
|
||||
const obj2 = {
|
||||
name: '许嵩',
|
||||
sex: '男',
|
||||
};
|
||||
|
||||
// 浅拷贝:把 obj1 赋值给 obj2。这一行,是关键代码
|
||||
Object.assign(obj2, obj1);
|
||||
|
||||
console.log(JSON.stringify(obj2));
|
||||
```
|
||||
|
||||
打印结果:
|
||||
|
||||
```
|
||||
{"name":"qianguyihao","sex":"男","age":28,"desc":"hello world"}
|
||||
```
|
||||
|
||||
注意,**例 4 在实际开发中,会经常遇到,一定要掌握**。它的作用是:将 obj1 的值追加到 obj2 中。如果两个对象里的属性名相同,则 obj12 中的值会被 obj2 中的值覆盖。
|
||||
|
||||
|
||||
## 深拷贝的实现方式
|
||||
|
||||
深拷贝其实就是将浅拷贝进行递归。
|
||||
|
@ -605,6 +605,10 @@ export default {
|
||||
|
||||
大功告成。本文感谢 ld 同学的支持。
|
||||
|
||||
更多内容,可以看本人的另外一篇文章:
|
||||
|
||||
- [AntD框架的upload组件上传图片时使用customRequest方法自定义上传行为](https://www.cnblogs.com/qianguyihao/p/13093592.html)
|
||||
|
||||
## 其他问题
|
||||
|
||||
- [beforeUpload返回false后,文件仍然为上传中的状态](https://github.com/ant-design/ant-design/issues/8779)
|
||||
@ -613,6 +617,5 @@ export default {
|
||||
|
||||
有人说,前端开发,连卖菜的都会。可如果真的遇到技术难题,还是得找个靠谱的前端同学才行。这不,来看看前端码农日常:
|
||||
|
||||
![](http://img.smyhvae.com/20190302_1339.png)
|
||||
|
||||
![](http://img.smyhvae.com/20190302_1339_2.png)
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
|
||||
|
||||
### 2019-04-26
|
||||
|
||||
- [一名【合格】前端工程师的自检清单](https://juejin.im/post/5cc1da82f265da036023b628)
|
||||
|
||||
|
||||
### 2020-05-14
|
||||
|
||||
- [React中setState的怪异行为 ——setState没有即时生效](https://blog.csdn.net/handsomexiaominge/article/details/86348235)
|
||||
|
Loading…
Reference in New Issue
Block a user