Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yaoyaohu
committed
Sep 21, 2019
1 parent
0055163
commit 2f551fc
Showing
15 changed files
with
560 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# 作用域相关问题 | ||
|
||
### 下面的代码打印什么内容,为什么? | ||
```js | ||
// 情况 1 | ||
|
||
// 情况 2 | ||
var b = 10; | ||
var c = function b() { | ||
b = 20; | ||
console.log(b) | ||
} | ||
c() | ||
|
||
// 上面两种都打印: | ||
ƒ b() { | ||
b = 20; | ||
console.log(b) | ||
} | ||
``` | ||
b函数(函数表达式定义函数)是一个相当于用const定义的常量,内部无法进行重新赋值,如果在严格模式下,会报错"Uncaught TypeError: Assignment to constant variable." | ||
|
||
### 简单改造下面的代码,使之分别打印 10 和 20 | ||
```js | ||
var b = 10; | ||
(function b() { | ||
b = 20; | ||
console.log(b) | ||
})() | ||
``` | ||
|
||
打印10: | ||
```js | ||
var b = 10; | ||
(function b(b) { | ||
window.b = 20; | ||
console.log(b) | ||
})(b) | ||
``` | ||
```js | ||
var b = 10; | ||
(function b() { | ||
b.b = 20; | ||
console.log(b) | ||
})() | ||
``` | ||
|
||
打印20: | ||
```js | ||
var b = 10; | ||
(function b(b) { | ||
b = 20; | ||
console.log(b) | ||
})() | ||
``` | ||
```js | ||
var b = 10; | ||
(function b() { | ||
var b = 20; | ||
console.log(b) | ||
})() | ||
``` | ||
|
||
### 下面代码输出什么 | ||
```js | ||
var a = 10; | ||
(function () { | ||
console.log(a) | ||
a = 5 | ||
console.log(window.a) | ||
var a = 20; | ||
console.log(a) | ||
})() | ||
``` | ||
依次输出:undefined -> 10 -> 20 | ||
|
||
解析: | ||
|
||
在立即执行函数中,var a = 20; 语句定义了一个局部变量 a,**由于js的变量声明提升机制**,局部变量a的声明会被提升至立即执行函数的函数体最上方,且由于这样的提升并不包括赋值,因此第一条打印语句会打印undefined,最后一条语句会打印20。 | ||
|
||
由于全局的var 会挂载到window对象下,并且立即执行函数里面有变量提示。 | ||
‘a = 5;’这条语句执行时,局部的变量a已经声明,因此它产生的效果是对局部的变量a赋值,此时window.a 依旧是最开始赋值的10 | ||
|
||
|
||
### var变量定义提升 | ||
```js | ||
var name = 'Tom'; | ||
(function() { | ||
if (typeof name == 'undefined') { | ||
var name = 'Jack'; | ||
console.log('Goodbye ' + name); | ||
} else { | ||
console.log('Hello ' + name); | ||
} | ||
})(); | ||
``` | ||
输出: 'Goodbye Jack' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- [GitHub最全前端资源汇总](http://fenghub.top/front-end-index/index.html) | ||
- [前端进阶之道](https://yuchengkai.cn/) | ||
- [有关React,你需要知道的一切](https://github.com/hateonion/react-bits-CN) | ||
- [木易杨-壹题](https://muyiy.cn/question/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 操作系统 | ||
|
||
参考资源:https://frank-lam.github.io/fullstack-tutorial/#/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F | ||
|
||
|
||
### CPU组成 | ||
CPU是由运算器和控制器这两个部分组成的。 | ||
|
||
1、运算器由算术逻辑单元(ALU)、累加器、状态寄存器、通用寄存器组等组成。算术逻辑运算单元(ALU)的基本功能为加、减、乘、除四则运算,与、或、非、异或等逻辑操作,以及移位、求补等操作。 | ||
|
||
计算机运行时,运算器的操作和操作种类由控制器决定。运算器处理的数据来自存储器;处理后的结果数据通常送回存储器,或暂时寄存在运算器中。与Control Unit共同组成了CPU的核心部分。 | ||
|
||
2、控制器分组合逻辑控制器和微程序控制器,两种控制器各有长处和短处。组合逻辑控制器设计麻烦,结构复杂,一旦设计完成,就不能再修改或扩充,但它的速度快。 | ||
|
||
微程序控制器设计方便,结构简单,修改或扩充都方便,修改一条机器指令的功能,只需重编所对应的微程序; | ||
|
||
要增加一条机器指令,只需在控制存储器中增加一段微程序,但是,它是通过执行一段微程。具体对比如下:组合逻辑控制器又称硬布线控制器,由逻辑电路构成,完全靠硬件来实现指令的功能。 |
Oops, something went wrong.