鱼C论坛

 找回密码
 立即注册
查看: 2760|回复: 0

[学习笔记] es6语法之类和对象

[复制链接]
发表于 2017-7-14 12:06:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这个就跟python的类差不多,语法非常简单
  1. class Person{
  2.         constructor(name) {
  3.             this.name=name
  4.                
  5.         }
  6. }
  7. let a= new Person('小甲鱼')
  8. document.write(a.name)
复制代码

里面的constructor是语法规定的构造器,网页显示为:
asdasasd.png


  1. class Animal{
  2.         fish(){
  3.                 return ['鲤鱼','黄花鱼','鱿鱼']
  4. }

  5. }

  6. class Person extends Animal{
  7.         constructor(fish) {
  8.                 super(fish)
  9.                
  10.         }
  11. }
  12. let a= new Person()
  13. document.write(a.fish())
复制代码

可以用extends关键字继承,网页显示为:
asadssdas.png



  1. class Animal{
  2.         static fish(){
  3.                 return ['鲤鱼','黄花鱼','鱿鱼']
  4. }

  5. }
  6. document.write(Animal.fish())
复制代码

静态属性就加个static关键字就行了,网页显示为:
sasasa.png

评分

参与人数 2荣誉 +6 鱼币 +6 收起 理由
不二如是 + 3 + 3
小甲鱼 + 3 + 3 支持楼主!

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-2 05:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表