let User = class {
constructor(uname,email){
// (1)属性
this.uname = uname
this.email = email
}
//(2)方法
say(){
return ${this.uname}:(${this.email})
}
//(3)静态成员
static nation = ‘CHINA’
}
// let User =new User(‘李小姐’,’asd@qq.com’)
const user = new User(‘李小姐’,’asd@qq.com’)
console.log(user,say)
console.log(“———————-“)
class child extends User {
constructor(uname,email,sex){
super(uname,email)
this.sex =sex
}
say () {
//super.say()父类中的say()
return `${super.say()},(${this.sex})`
}
}
const child =new Child (‘王小姐’,’asd@qq.com’,’女’)
console.log(child.say())
console.log(‘——————————-‘)
let str = ‘PHP中文网’
// 0 ->p
// 1 ->h
// 2 ->p
// 3 ->中
// 4 ->文
// 5 ->网
console.log(‘length= ‘,str.length)
//把要索引的位数引入则可得
console.log(str[5])
console.log(str.indexOf(‘中’))
// ()网的左右字符串替换
console.log(str.replace(‘中文网’,’.cn’))
//把前面三个转成数组
console.log(str.split(‘’,3))
console.log(‘PHP.CN’.toLocaleLowerCase())
console.log(‘www.php.cn’.toUpperCase())
console.log(‘—————————-‘)
let n = [1,2,3]
let n1 = […n]
console.log(n1)
// 更新.展示数组表达
n = […n,4,5]
console.log(n)
console.log(‘———————‘)
let f = [1,2,3,4,5,6]
console.log(Array.of(…f))
console.log(‘———————‘)
const likeArr = {
0:’d’,
1:’s’,
2:’h’,
length:3,
}
const data = Array.from(likeArr)
// for-of关注值
for (let item of data) {
console.log(item)
}
console.log(‘———————‘)
let arr = []
//从尾部添加
console.log(arr.push(10))
console.log(arr.pop())
//从头部添加
console.log.apply(arr.unshift(1))
console.log(arr.shift())
//删除数组
arr1 = [1,2,3,4]
//删除第二个数组(2)
delete arr1 [1]
console.log(arr1)
console.log(‘———————‘)
let arr2 = [1,2,3,4,5]
//forEach 没有返回值
arr2.forEach(function(item,key,arr){
console.log(item,key,arr)
})
//map 有返回
let result = arr2.map(function(item,key,arr){
return item
// return key
// return arr
})
console.log(result)
arr3 = [1, 2, 3, 4, 5]
result = arr3.reduce(function (acc,cur,key,arr3) {
console.log(acc=${acc},cur=${cur},key=${key},arr3=[${arr3}]
)
return acc + cur
},0)
console.log(result)