es7 es6(class,字符串?dāng)U展,數(shù)值擴(kuò)展,數(shù)組擴(kuò)展,對(duì)象擴(kuò)展)

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>Title</title>

</head>

<body>

<!--

1. 指數(shù)運(yùn)算符(冪): **

2. Array.prototype.includes(value) : 判斷數(shù)組中是否包含指定value

-->

<script type="text/javascript">

console.log(2**3);//8

let arr = [1,4,5,6,'abc'];

console.log(arr.includes('a'));//false

console.log(arr.includes('abc'));//true

console.log(arr.includes(4))//true

</script>

</body>

</html>

class

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>12_class</title>

</head>

<body>

</body>

<!--

1. 通過(guò)class定義類/實(shí)現(xiàn)類的繼承

2. 在類中通過(guò)constructor定義構(gòu)造方法

3. 通過(guò)new來(lái)創(chuàng)建類的實(shí)例

4. 通過(guò)extends來(lái)實(shí)現(xiàn)類的繼承

5. 通過(guò)super調(diào)用父類的構(gòu)造方法

6. 重寫(xiě)從父類中繼承的一般方法

-->

<script type="text/javascript">

// function Person(name,age){

// this.name = name;

// this.age = age;

// }

// let person = new Person('kobe',40);

// console.log(person);

class Person{

//類的構(gòu)造方法 相當(dāng)于Python的__init__

constructor(name,age){

this.name = name;

this.age = age;

}

//類的一般方法

showName(){

console.log('調(diào)用父類的方法');

console.log(this.name,this.age);

}

}

//子類 Python寫(xiě)法:class StarPerson(Person):

class StarPerson extends Person{

constructor(name,age,salary){

super(name,age);//調(diào)用父類的構(gòu)造方法

this.salary = salary;

}

//父類方法的重寫(xiě)

showName(){

console.log('調(diào)用子類的方法');

console.log(this.name,this.age,this.salary);

}

}

let person = new Person('kobe',40);

console.log(person);

// person.showName();

let sp = new StarPerson('wade',36,1243254360);

console.log(sp);

sp.showName();

</script>

</html>

字符串?dāng)U展

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>01_字符串?dāng)U展</title>

</head>

<body>

<!--

1. includes(str) : 判斷是否包含指定的字符串

2. startsWith(str) : 判斷是否以指定字符串開(kāi)頭

3. endsWith(str) : 判斷是否以指定字符串結(jié)尾

4. repeat(count) : 重復(fù)指定次數(shù)

-->

<script type="text/javascript">

let str = 'adfasdawohenfiinwegk';//true

console.log(str.includes('a'));//true

console.log(str.startsWith('a'));//true

console.log(str.endsWith('k'));//true

console.log(str.repeat(3));//重復(fù)三次

</script>

</body>

</html>

數(shù)值的擴(kuò)展

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>02_數(shù)值擴(kuò)展</title>

</head>

<body>

<!--

1. 二進(jìn)制與八進(jìn)制數(shù)值表示法: 二進(jìn)制用0b, 八進(jìn)制用0o

2. Number.isFinite(i) : 判斷是否是有限大的數(shù)

3. Number.isNaN(i) : 判斷是否是NaN

4. Number.isInteger(i) : 判斷是否是整數(shù)

5. Number.parseInt(str) : 將字符串轉(zhuǎn)換為對(duì)應(yīng)的數(shù)值

6. Math.trunc(i) : 直接去除小數(shù)部分

-->

<script type="text/javascript">

console.log(0b1010);//10

console.log(0o56);//46

console.log(Number.isFinite(123));//true

console.log(Number.isFinite(Infinity));//false

console.log(Number.isNaN(NaN));//true

console.log(Number.isInteger(123));//true

console.log(Number.isInteger(123.456));//false

console.log(Number.isInteger(123.0));//true

console.log(Number.parseInt('123abc456'));//123

console.log(Number.parseInt('a123abc456'));//NaN

console.log(Math.trunc(123.123));//123

</script>

</body>

</html>

數(shù)組的擴(kuò)展

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>03_數(shù)組擴(kuò)展</title>

</head>

<body>

<button>測(cè)試1</button>

<br>

<button>測(cè)試2</button>

<br>

<button>測(cè)試3</button>

<br>

<!--

1. Array.from(v) : 將偽數(shù)組對(duì)象或可遍歷對(duì)象轉(zhuǎn)換為真數(shù)組

2. Array.of(v1, v2, v3) : 將一系列值轉(zhuǎn)換成數(shù)組

3. find(function(value, index, arr){return true}) : 找出第一個(gè)滿足條件返回true的元素

4. findIndex(function(value, index, arr){return true}) : 找出第一個(gè)滿足條件返回true的元素下標(biāo)

-->

<script type="text/javascript">

let btns = document.getElementsByTagName('button');

Array.from(btns).forEach(function(item,index){

console.log(item);

})

let arr = Array.of(1,4,'abc',true);

console.log(arr);//[1,4,'abc',true]

let arr2 = [2,3,4,2,5,7,3,6,5];

let result = arr2.find(function(item,index){

return item > 4;

})

console.log(result);//5

result = arr2.findIndex(function(item,index){

return item > 4;

})

console.log(result);//4(5的下標(biāo))

</script>

</body>

</html>

對(duì)象擴(kuò)展

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <title>04_對(duì)象擴(kuò)展</title>

</head>

<body>

<!--

1. Object.is(v1, v2)

? * 判斷2個(gè)數(shù)據(jù)是否完全相等

2. Object.assign(target, source1, source2..)

? * 將源對(duì)象的屬性復(fù)制到目標(biāo)對(duì)象上

3. 直接操作 __proto__ 屬性

? let obj2 = {};

? obj2.__proto__ = obj1;

-->

<script type="text/javascript">

console.log(0 == -0);//true

console.log(NaN == NaN);//false

console.log(Object.is(0,-0));//false

console.log(Object.is(NaN,NaN));//true

let obj = {};

let obj1 = {username:'iverson',age:43};

let obj2 = {sex:'男'};

Object.assign(obj,obj1,obj2);

console.log(obj);//{username:'iverson',age:43,sex:'男'};

let obj3 = {};

let obj4 = {money: 5050000};

boj3.__proto__= obj4;

console.log(obj3)

console.log(obj3.money);

</script>

</body>

</html>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容