当前位置: 首页 > news >正文

面向对象的js

构造函数

<script>
function Student(uname,age.height){
//this指向实例化出来的对象本身
this.name=uname
this.age=age
this.height=height
this.walk=function(){
console.log("walk")
}
}
//new关键字进项实例化
const obj1=new Student("alice",22,170)
console.log(obj1.name)
const obj2=new Student("jone",23,188)
console.log(obj2.name)//完全独立
//问题:walk代码冗余
//作用域被扩大
function walk(){
console.log("walk")
}
Student.prototype//原型对象
</script>

原型对象 通过构造函数的原型对象所分配的函数,是被所有的通过该构造函数创建的对象所共享的

console.log(arr1.__proto__)——指向arr1原型函数

继承

<script>
function Parent(){
this.name="zhangsan"
this.colors=["red","yellow"]
}
Parent.prototype.sing=dunction(){
cinsole.log("father sing~~~~")
}
funxtion Child(){
this.age=21
}
Child.prototype=new Parent()
let c1=new Child()
c1.colors=["pink","green","zhangsan"]
c1.colors.append("zhangsan")
let c2=new Child()
console.log(c1.colors===c2.colors)
//继承的属性会被child实例化的对象共享
//无法对父亲的参数进行传参
</script>

ajax发生请求

<button onlick="load">点击发生请求</button>
<script>                                                                               
function load(){
//创建XMLHttprequest
let xhe=new XMLHttprequest
//指定请求方式 get 请求的url地址
xhr.open("GET","URL",true)
//设置响应的数据处理
xhr.onreadystatechange=function(){
if(xhr.readyState===4&&xhr.status===200)//4表示请求已经完成且响应结果已经接收
//处理响应的数据
let data=JSON.parse(xhr.responseText)
let newli=document.createElement("li")
newli.innerHTML 
}
}
xhr.send()
}

异常处理

<script>
try{
console.log(12/0)
}catch(error){
console.log("除数不难为0")
}
</script>

json

http://www.xdnf.cn/news/409213.html

相关文章:

  • 短视频兴趣算法的实现原理与技术架构
  • Linux512 ssh免密登录 ssh配置回顾
  • 写项目遇到的通用问题
  • Windows 安装 Milvus
  • 论坛项目测试
  • Matlab 模糊pid控制的永磁同步电机PMSM
  • 前端面经 计网 http和https区别
  • ​Spring Boot 配置文件敏感信息加密:Jasypt 实战
  • 国产密码新时代!华测国密 SSL 证书解锁安全新高度
  • 开疆智能canopen转Profinet网关连接AGV磁钉读头配置案例
  • HTTP2
  • Java中实现定时器的常见方式
  • C 语 言 - - - 简 易 通 讯 录
  • 网页Web端无人机直播RTSP视频流,无需服务器转码,延迟300毫秒
  • 致远OA人事标准模块功能简介【附应用包百度网盘下载地址,官方售价4W】
  • OpenCV直方图与直方图均衡化
  • Unity动画系统使用整理 --- Playable
  • python标准库--collections - 高性能数据结构在算法比赛的应用
  • LVGL(线条控件lv_line)
  • CentOS 和 RHEL
  • FPGA----基于ZYNQ 7020实现定制化的EPICS程序开发
  • AI Agent开发第64课-DIFY和企业现有系统结合实现高可配置的智能零售AI Agent
  • 智能外呼系统的实用性
  • LGDRL:基于大型语言模型的深度强化学习在自动驾驶决策中的应用
  • bea算法,大模型
  • Linux文件系统
  • C++11新特性(1)
  • Aware和InitializingBean接口以及@Autowired注解失效分析
  • 内存泄漏系列专题分析之十一:高通相机CamX ION/dmabuf内存管理机制Camx ImageBuffer原理
  • 【论信息系统项目的质量管理】