JavaScript -- Part1

Map和Set的区别,Map和Object的区别

https://blog.csdn.net/muzidigbig/article/details/121995777

数组的filter、every、flat的作用是什么

es6有哪些新特性 :star:

说一下对Promise的了解 :star:

Promise的all和race :star:

箭头函数和普通函数的区别 :star:

let、var和const的区别 :star:

如果希望const定义的对象的属性也不能被修改该怎么做 ?

使用Object.freeze(obj)冻结obj,就能使其内部的属性不可变,但有局限,就是obj对象中要是有属性是对象,该对象内属性还能改变,要全不可变的话,就需要使用递归等方式一层一层全部冻结。

闭包的原理 :star:

instanceof 的实现原理 :star:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function custumInstanceOf(left, right) {
if (typeof left !== 'object' || left === null) return;
let rightProto = right.prototype
let leftProto = left.__proto__
while(true) {
if (leftProto === null) {
return false
} else if (leftProto === rightProto) {
return true
}
leftProto = leftProto.__proto__
}
}
function Person (age, name) {
this.age = age
this.name = name
}
const jack = new Person(18, 'hlc')
console.log(custumInstanceOf(jack, Person))

new的实现原理 :star:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Person (age, name) {
this.age = age
this.name = name
}

const jack = new Person(18, 'hlc')
console.log(jack)

function newFunc() {
let [constructor, ...args] = [...arguments]
let newObj = {}
newObj.__proto__ = constructor.prototype
let result = constructor.apply(newObj, args)
// 因为有的构造函数返回的是一个对象或者函数,所有进行以下处理
if (result && typeof result === 'function' || typeof result === 'object') {
return result
}
return newObj
}

const lyric = newFunc(Person, 18, 'tsouling')
console.log(lyric)

数据类型有哪些?如何判断一个数据是否是数组 :star::star:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function myTypeOf (val) {
if (typeof val === 'object' ) {
return Object.prototype.toString.call(val).match(/\w+(?=\])/)[0].toLowerCase()
} else {
return typeof val
}
}
console.log(myTypeOf([1,2]))
console.log(myTypeOf({}))
console.log(myTypeOf(/dfdf/))
console.log(myTypeOf(new Date()))
console.log(myTypeOf(Object.keys))
console.log(myTypeOf(null))
console.log(myTypeOf(undefined))
console.log(myTypeOf(1))
console.log(myTypeOf('2'))
console.log(myTypeOf(true))

JQuery实现链式调用的原理是什么

链式调用的原理就是实例在调用内部方法的时候,返回当前调用这个方法的实例对象this就可以了,因为返回了当前的this就可以继续访问自己的原型了。 jQuery的这种管道风格的DSL链式代码,总的来说: 节约JS代码; 所返回的都是同一个对象,可以提高代码的效率。


JavaScript -- Part1
http://example.com/2022/08/12/JavaScript-Part1/
作者
lyric
发布于
2022年8月12日
许可协议