JS基础功能

1. 生成0-20的数组

Array.from({ length: 20 }, (v, i) => i)

2. Object.create(proto)

以现有对象作为原型,创建一个新对象
image

  • 用于实现类式继承
    image
  • 字面量初始化对象语法是Objec.create()的一种语法糖
o = {} 等价于
o = Object.create(Object.prototype)

3. Object.getOwnPropertyNames()

返回给定对象中所有自有属性,包括不可枚举属性,不包括symbol

4. Object.getPrototypeOf()

返回指定对象的原型

const proto = {}
cons obj = Object.create(proto)
Object.getPrototypeOf(obj) === proto

5. Function.length

函数期望的参数数量,不包括剩余参数,只包括在第一个具有默认值的参数之前的参数
image

6. Arguments对象

对应于传递给函数参数的类数组对象

6. 类数组转化为数组

哪些是类数组?arguments,NodesList,HTMLCollection

Array.prototype.slice.call(arguments)
[].slice.call(arguments)
Array.from(arguments)
[...arguments]
posted @ 2023-09-20 16:07  躺尸的大笨鸟  阅读(9)  评论(0)    收藏  举报