首页 > 编程语言 >5.JS面向对象编程

5.JS面向对象编程

时间:2022-09-07 20:56:27浏览次数:72  
标签:xiaoming name student hello JS 面向对象编程 var class

5.面向对象编程

5.1 原型对象

JavaScript,java,c#。。。。

类:模板

对象:具体的实例

原型:

  var user={
      name:"cc",
      age:3,
      sex:'男',
      run:function () {
          console.log(this.name+"run...")
      }
  }
  var xiaoming={
      name:"xiaoming"
  }
  //小明的原型就是user
 xiaoming.__proto__=user

class继承

class关键字是在ES6引入的

1.定义一个类,属性,方法

 class student{
     constructor(name) {
         this.name = name;
    }
         hello(){
             alert('hello')
        }
 }

2.继承

 //定义一个学生类
     class student{
         constructor(name) {
             this.name = name;
        }
             hello(){
                 alert('hello')
            }
    }
     class xiaostudent extends student{
         constructor(name,grade) {
             super(name);
             this.grade=grade;
        }
         myGrade(){
             alert('我是小学生')
        }
    }
     var xiaoming=new student("xiaoming")
     var xiaohong=new xiaostudent("xiaohong",100)

原型链

__ proto__

 

标签:xiaoming,name,student,hello,JS,面向对象编程,var,class
From: https://www.cnblogs.com/cyh822blogs/p/16667210.html

相关文章

  • 16.1json模块 16.2文件上传 16.3session的高级用法
    16.1json模块#json主要是干嘛的?json非常严格的数据类型,只能用“”,不然会报错,只支持""#把一个东西变成序列#[1,2,3,4,5]#有序的叫序列#{"a",'b'}#散列#importjson......
  • JS: 模拟async/await语法糖
    不熟悉生成器对象的小伙伴,可查看:Generator、Generator.prototype.next模拟函数:/***模拟async关键字的函数*(不返回Promise对象也是可以的)*@paramgenerator*......
  • 包和模块、库、json库
    七.包和模块package:针对代码结构的组织,一个包里面可以拥有很多的python文件module:一个python文件就是一个模块1.从另一个模块直接引用所需代码模块必须是存放在......
  • 10.1纯函数面向对象编程
    #人狗大战#人-角色#名称等级血量攻击力性别职业#zhangsan={'name':"zhangsan",'level':1,'hp':200,'ad':40,'性别':'不详','职业':'射手'}##l......
  • 面向对象编程
    背景:1.游戏引擎运行于操作系统上,操作系统又运行于特定的硬件(CUP/RAM/IO)上,因此硬件的瓶颈会限制游戏引擎的性能;2.由于摩尔定律接近天花板,芯片上晶体管的密集程度再增加的话......
  • js 实现扁平数组转为树形结构数组及树形结构数组转为扁平数组
    //pid代表属于的父级id//id代表的是自己本身的id,本身的id是多少letflatArr=[{id:1,name:"部门1",pid:0},{id:2,name:"部门2",pid:1}......
  • vue.js3:图片镜像(翻转)并保存([email protected])
    一,js代码:<template><divstyle="background:#ffffff;"id="root"><div><button@click="restore">还原</button><button@click="flipx">水平镜像</button>......
  • autojs
    functionunlock(){if(!device.isScreenOn()){device.wakeUp();sleep(500);swipe(500,2000,500,1000,210);sleep(500)......
  • 4.JS内部对象
    4.内部对象标准对象4.1Date typeof123 'number' typeof'123' 'string' typeoftrue 'boolean' typeofNaN 'number' typeof[] 'object' typeof{} 'o......
  • JS笔记
     1.js获取map的键:bosType:"353E3C6E"dynamic_Field37:falsedynamic_Field39:bankAccountNumber:"45001604255060414843"bosType:"FB326E5E"id:"KggAA......