Blogger Information
Blog 19
fans 0
comment 0
visits 10714
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
class类与extends,super等的用法与字符串,数组常用API
牙森江
Original
324 people have browsed it

1.class类与extends,super等的用法

1.1 class类

=>1.构造函数并声明->属性->2.方法->3.静态成员

  1. let User = class {
  2. constructor(uname, email) {
  3. this.uname = uname
  4. this.email = email
  5. }
  6. say() {
  7. return `${this.uname}: ( ${this.email} )`
  8. }
  9. static nation = '中国'
  10. }
  11. const user = new User('Mr.Y', 'mmmyyy@qq.com')
  12. console.log(user.say())
  13. console.log(User.nation)
  14. 运行结果:
  15. Mr.Y: ( mmmyyy@qq.com )
  16. 中国

1.2 extends,super的用法

  1. class Child extends User {
  2. constructor(uname, email, gender) {
  3. super(uname, email)
  4. this.gender = gender
  5. }
  6. say() {
  7. return `${super.say()}, (${this.gender})`
  8. }
  9. }
  10. const child = new Child('黄氏', 'hs@qq.com', '男')
  11. console.log(child.say())
  12. 运行结果:
  13. 黄氏: ( hs@qq.com ), (男)

2.字符串,数组常用API

2.1.length 属性

  1. let xName = 'My name is Yasinjan'
  2. console.log('length = ', xName.length)
  3. 运行结果:
  4. length = 19

2.2 charAt(), 索引 -> 成员

  1. let xName = 'My name is Yasinjan'
  2. console.log(xName[4])
  3. 运行结果:
  4. a

2.3 indexOf(): 成员 -> 索引

  1. let xName = 'My name is Yasinjan'
  2. console.log(xName.indexOf('Y'))
  3. 运行结果:
  4. 11

2.4 replace()替换

  1. let xName = 'My name is Yasinjan'
  2. console.log(xName.replace('Yasinjan', 'GongLi'))
  3. 运行结果:
  4. My name is GongLi

2.5 split: 字符串 -> 数组

  1. let xName = 'My name is Yasinjan'
  2. console.log(xName.split('', 5))
  3. 运行结果:
  4. [ 'M', 'y', ' ', 'n', 'a' ]
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的很好, 没什么问题
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post