Skip to content

Commit 16e12c6

Browse files
committed
style: eslint code
1 parent 05345d9 commit 16e12c6

File tree

16 files changed

+54
-57
lines changed

16 files changed

+54
-57
lines changed

code/algorithm/interview-101/binarySearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
*
55
*/
6-
const search = function (nums, target) {
6+
function search(nums, target) {
77
// 投机
88
// return nums.indexOf(target)
99

code/express/apps/static-source-demo/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const express = require('express')
22

33
const app = express()
4-
// eslint-disable-next-line import/order
4+
55
const path = require('node:path')
66
// 服务启动端口
77
const port = 3000

code/express/apps/template-demo/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const path = require('node:path')
21
const http = require('node:http')
3-
const createError = require('http-errors')
4-
const express = require('express')
2+
const path = require('node:path')
53
const cookieParser = require('cookie-parser')
4+
const express = require('express')
5+
const createError = require('http-errors')
66
const logger = require('morgan')
77
const indexRouter = require('./routes/index')
88
const usersRouter = require('./routes/users')

code/koa/koa-listen.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/order
21
const Koa = require('koa')
32

43
const app = new Koa()

docs/front-end/base-begin/javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function fn() {
315315

316316
```js
317317
// 匿名函数
318-
const fn = function () {
318+
function fn() {
319319

320320
}
321321
```

docs/read-books/cs-books/ES6标准入门.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ function objectConstant(obj) {
544544
: this)
545545

546546
// 方法二
547-
const getGlobal = function () {
547+
function getGlobal() {
548548
if (typeof self !== 'undefined') {
549549
return self
550550
}
@@ -2315,7 +2315,7 @@ ES6 对这个属性的行为做出了一些修改,如果将一个匿名函数
23152315

23162316
```js
23172317
// 匿名函数
2318-
const f = function () {
2318+
function f() {
23192319
}
23202320

23212321
// ES5
@@ -2328,7 +2328,7 @@ f.name // "f"
23282328
如果将一个具名函数赋值给一个变量,则 ES5 和 ES6 的name属性都返回这个具名函数原本的名字。
23292329

23302330
```js
2331-
const bar = function test() {
2331+
function bar() {
23322332
}
23332333

23342334
// ES5
@@ -3094,9 +3094,9 @@ Array.of(3).length // 1
30943094
弥补数组构造函数`Array()`的不足。因为参数个数的不同,会导致`Array()`的行为有差异。
30953095

30963096
```js
3097-
Array() // []
3098-
Array(3) // [, , ,]
3099-
Array(3, 11, 8) // [3, 11, 8]
3097+
new Array() // []
3098+
Array.from({ length: 3 }) // [, , ,]
3099+
new Array(3, 11, 8) // [3, 11, 8]
31003100
```
31013101

31023102
`Array()`方法没有参数、一个参数、三个参数时,返回的结果都不一样。
@@ -3430,7 +3430,7 @@ arr.flatMap(function callback(currentValue[, index[, array]]) {
34303430

34313431
```js
34323432
// 返回具有 3 个空位的数组。
3433-
Array(3) // [, , ,]
3433+
Array.from({ length: 3 }) // [, , ,]
34343434
```
34353435

34363436
空位不是`undefined`,一个位置的值等于`undefined`,依然是有值的。**空位是没有任何值**,in运算符可以说明这一点。
@@ -3833,7 +3833,7 @@ descriptor.set.name // "set foo"
38333833
```js
38343834
(new Function()).name // "anonymous"
38353835

3836-
const doSomething = function () {
3836+
function doSomething() {
38373837
// ...
38383838
}
38393839
doSomething.bind().name // "bound doSomething"
@@ -4328,9 +4328,9 @@ console.log(obj) // { "0": "a", "1": "b", "2": "c" }
43284328
只有字符串合入目标对象(以字符数组的形式),数值和布尔值都会被忽略。**因为只有字符串的包装对象,会产生可枚举属性。**
43294329
43304330
```js
4331-
Object(true) // {[[PrimitiveValue]]: true}
4332-
Object(10) // {[[PrimitiveValue]]: 10}
4333-
Object('abc') // {0: "a", 1: "b", 2: "c", length: 3, [[PrimitiveValue]]: "abc"}
4331+
new Object(true) // {[[PrimitiveValue]]: true}
4332+
new Object(10) // {[[PrimitiveValue]]: 10}
4333+
new Object('abc') // {0: "a", 1: "b", 2: "c", length: 3, [[PrimitiveValue]]: "abc"}
43344334
```
43354335
43364336
`布尔值``数值``字符串`分别转成对应的包装对象,可以看到它们的原始值都在包装对象的内部属性`[[PrimitiveValue]]`
@@ -4606,7 +4606,7 @@ obj.method = function () {
46064606
```js
46074607
Object.defineProperty(Object.prototype, '__proto__', {
46084608
get() {
4609-
const _thisObj = Object(this)
4609+
const _thisObj = new Object(this)
46104610
return Object.getPrototypeOf(_thisObj)
46114611
},
46124612
set(proto) {

docs/read-books/cs-books/更了不起的Node.js.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ Node.js是基于CommonJS规范的实现,即每个文件都是一个模块,
261261
```js
262262
// 相关模块
263263

264-
const http = require('node:http')
265264
const fs = require('node:fs')
265+
const http = require('node:http')
266266

267267
// 实例化对象
268268

@@ -717,7 +717,7 @@ Node.js对模块的定义非常简单,主要分为模块应用、模块定义
717717
> 可以将关联代码封装到一个代码单元中,创建一个模块可以理解为全部有关联的函数放在一个文件中
718718
719719
```js
720-
const sayHelloEnglish = function () {
720+
function sayHelloEnglish() {
721721
return 'hello'
722722
}
723723

docs/read-books/cs-books/深入浅出的Node.js.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ web服务器的会话实现一般通过内存来存储,**当访问量大的时
379379

380380
```js
381381
// test函数 local局部变量
382-
const test = function () {
382+
function test() {
383383
const local = {}
384384
}
385385
```
@@ -419,7 +419,7 @@ Tips:同样,在非全局作用域中,想要主动释放变量引用的对
419419
主要是通过高阶函数的特性(函数可以作为参数或者返回值)完成的
420420

421421
```js
422-
const foo = function () {
422+
function foo() {
423423
const bar = function () {
424424
// 定义局部变量
425425
const local = '局部变量'
@@ -496,7 +496,7 @@ Node对内存泄露非常敏感,一旦线上项目应用拥有成千上万的
496496
// 例如利用cache全局对象来常驻老生代内存中
497497
const cache = {}
498498
// 获取目标值
499-
const get = function (key) {
499+
function get(key) {
500500
if (cache[key]) {
501501
// 内存中存在,即返回
502502
return cache[key]
@@ -507,7 +507,7 @@ const get = function (key) {
507507
}
508508

509509
// 设置key/value值
510-
const set = function (key, value) {
510+
function set(key, value) {
511511
// 设置
512512
cache[key] = value
513513
}

docs/server-end/design-patterns/技巧型模式/数据访问对象模式.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ permalink: /server-end/design-patterns/data-access-object-mode.html
2626
* @param {string} prefix Key前缀
2727
* @param {string} timeSplit 时间戳与存储数据之间的分割符
2828
*/
29-
const DAO = function (prefix, timeSplit) {
29+
function DAO(prefix, timeSplit) {
3030
this.prefix = prefix
3131
this.timeSplit = timeSplit || '|-|'
3232
}

docs/server-end/design-patterns/技巧型模式/等待者模式.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ permalink: /server-end/design-patterns/waiters-mode.html
2020
### 实现
2121

2222
```javascript
23-
const Waiter = function () {
23+
function Waiter() {
2424
let dfd = [] // 等待对象容器
2525
let doneArr = [] // 成功回调容器
2626
let failArr = [] // 失败回调容器
@@ -98,9 +98,7 @@ const Waiter = function () {
9898
failArr = failArr.concat(args) // 向失败回调函数中添加方法
9999
return this
100100
}
101-
}
102-
103-
;(function () {
101+
}(function () {
104102
const waiter = new Waiter() // 创建一个等待者实例
105103
const first = (function () {
106104
const promise = waiter.Deferred()

0 commit comments

Comments
 (0)