2018-01-26 15:18:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 方法的注释
|
|
|
|
|
|
|
|
|
|
|
2018-02-01 22:58:37 +08:00
|
|
|
|
方法写完之后(注意,一定要先写完整),我们在方法的前面输入`/**`,然后回车,会发现,注释的格式会自动补齐。
|
|
|
|
|
|
|
|
|
|
比如:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
/**
|
|
|
|
|
* 功能:给定元素查找他的第一个元素子节点,并返回
|
|
|
|
|
* @param ele
|
|
|
|
|
* @returns {Element|*|Node}
|
|
|
|
|
*/
|
|
|
|
|
function getFirstNode(ele){
|
|
|
|
|
var node = ele.firstElementChild || ele.firstChild;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
2018-01-26 15:18:56 +08:00
|
|
|
|
### 断点调试
|
|
|
|
|
|
|
|
|
|
(1)先让程序运行一遍。
|
|
|
|
|
|
|
|
|
|
(2)f12,弹出代码调试工具
|
|
|
|
|
|
|
|
|
|
(3)打断点:
|
|
|
|
|
|
|
|
|
|
![](http://img.smyhvae.com/20180124_2035.png)
|
|
|
|
|
|
|
|
|
|
然后刷新页面。
|
|
|
|
|
|
|
|
|
|
(4)一步步调试,每点击一次,执行一步:
|
|
|
|
|
|
|
|
|
|
![](http://img.smyhvae.com/20180124_2036.png)
|
|
|
|
|
|
|
|
|
|
(5)监视变量:
|
|
|
|
|
|
|
|
|
|
当然,也可以添加变量或者表达式到监视窗口。操作如下:
|
|
|
|
|
|
|
|
|
|
![](http://img.smyhvae.com/20180124_2037.png)
|
|
|
|
|
|
|
|
|
|
上图中,选择变量或表达式,然后右键add to watch.
|
|
|
|
|
|
|
|
|
|
然后监视窗口:
|
|
|
|
|
|
|
|
|
|
![](http://img.smyhvae.com/20180124_2038.png)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-23 11:16:39 +08:00
|
|
|
|
### 2019-05-20-给数组、对象赋值
|
|
|
|
|
|
|
|
|
|
**数组赋值的正确写法**:
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
this.todayList.splice(0, 0, ...dataList);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**对象赋值的正确写法**:
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
|
Object.assign(this.dataObj, dataObj);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
上方代码中,是将`dataObj` 的值追加到`this.dataObj`中。如果对象里属性名相同,会被覆盖。
|
2018-01-26 15:18:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|