Array.of()创建数组
Array.from(类数组,map函数,this指向)类数组转成数组
<script>
var arr = [];
var arr1 = new Array(11,22,33,"aa");
console.log(arr1);
console.log(Array.of(1, 2, 3, 4,"abc",{name:1},function a(){}));
console.log(Array.from([1, 2]))
</script>
find()
概念:查找数组中符合条件的元素,若有多个符合条件的元素,
则返回第一个元素。
<script>
var a = [1,2,3,4,5].find((item)=>{
return item>2
})
console.log(a);
</script>
findIndex()
1.查找数组中符合条件的元素索引,
2.若有多个符合条件的元素,则返回第一个元素索引。
3.没查找到返回-1
注意:数组里面改变this指向的方法 findIndex() find() Array.from() flatMap()
fill()将一定范围索引的数组元素内容填充为单个指定的值
参数1:用来填充的值
参数2:被填充的起始索引(包含)
参数3(可选):被填充的结束索引,默认为数组末尾(不包含),默认到最后
console.log([1, 2, 3, 4].fill(0,1,2));
copyWithin()将一定范围索引的数组元素修改为此数组另一指定范围索引的元素。
参数1:被修改的起始索引
参数2:被用来覆盖的数据的起始索引
参数3(可选):被用来覆盖的数据的结束索引,默认为数组末尾
概念:
1.class 的本质是 function。
2.不可重复声明。
3.类定义不会被提升,这意味着,必须在访问前对类进行定义,
否则就会报错。
4.类中方法不需要 function 关键字。
5.方法间不能加分号。
类定义
命名类
let Example = class Example{};
匿名类
let Examples = class{};
类的主体
属性:
属性值 | 含义 |
---|---|
prototype | 原型 |
static | 静态属性 |
class Example{}Example.prototype.a = 2; | 公共属性 |
class Example { a = 2;constructor () {console.log(this.a); }} | 实例属性 |
返回跟在 class 后的类名(存在时) | name 属性 |
静态属性:class 本身的属性,即直接定义在类内部的属性(Class.propname ),
不需要实例化。 ES6 中规定,Class 内部只有静态方法,没有静态属性。
constructor 方法
作用:检测类型
onstructor 方法是类的默认方法,创建类的实例化对象时被调用。
类的实例化
new
class 的实例化必须通过 new 关键字。
<script>
class Example{
constructor(){
console.log('我是constructor');
}
}
new Example(); // 我是constructor
</script>
静态成员
<script>
static a = 2;
static b = 80;
static sing(){
console.log(22222222);
};
sum(){
console.log(11111111);
}
</script>
返回对象
<script>
class Test {
constructor(){
// 默认返回实例对象 this
}
}
console.log(new Test() instanceof Test); // true
class Example {
constructor(){
// 指定返回对象
return new Test();
}
}
console.log(new Example() instanceof Example); // false
</script>