当前位置:网站首页>Object.defineProperty、回调函数、数组方法
Object.defineProperty、回调函数、数组方法
2022-07-19 07:45:00 【半夜删你代码·】
<body>
<script>
// Object.defineProperty是一个方法(函数)
// 函数三要素:功能 参数 返回值
// 功能:给对象添加或者修改属性,让这个属性是响应式的(这个属性改变引起其它的改变)
let obj = {
firstName:'zhao',
lastName:'liying'
}
// 下面这样的写法写死了,不是响应式的属性
// obj.fullName = 'zhao-liying'
// console.log(obj);
// obj.fullName = 'liu-yifei'
// console.log(obj);
Object.defineProperty(obj,'fullName',{
get(){
return this.firstName + '-' + this.lastName
},
set(val){
let arr = val.split('-')
this.firstName = arr[0]
this.lastName = arr[1]
}
})
console.log(obj.fullName);
obj.fullName = 'liu-yifei'
console.log(obj);
// 数据代理
let data = {
msg:'我爱你赵丽颖'
}
let vm = {
}
Object.defineProperty(vm,'msg',{
get(){
return data.msg
},
set(val){
data.msg = val
}
})
console.log(vm);
console.log(vm.msg);
</script>
</body>
函数和函数对象
函数就是函数,我们定义的时候都叫函数
函数在使用的时候是加() 使用我们称之为函数
函数如果是加.使用,那么我们就称之为函数对象
函数和构造函数
函数在使用的时候才会区分函数(普通函数调用)和构造函数(构造函数调用)
如果函数直接加() 就叫普通函数调用
如果函数加 new+() 就叫构造函数调用
配置对象: 键名不能更改 值可以改变的对象
回调函数
1.自己定义的 没有调用 但是最后执行了
2.事件源(浏览器控制事件源)调用回调函数
3.浏览器会把这一次触发的事件封装成对象传过去
4.高阶函数里面传递的也是回调函数
同步回调
结果出现在函数调用之后(数组方法,map..)
异步回调
结果出现在函数调用之前(setTomeout)
数组方法
边栏推荐
- Restore 360 favorites method after the computer is damaged and the system is reinstalled, put 360sefav_ new_ 2021_ 07_ 16. Favdb files are copied to other computers. Files containing the character new
- Wechat applet bindinput and click the button to assign the content of the current text
- Digital signal processing experiment II IIR digital filter design and software implementation
- 分布式笔记(04)— 分布式锁之 Redis(分布式锁实现、加锁流程、解锁流程、预防死锁、正确及错误的加解锁实现)
- Win7安装系统,无猫腻
- Software testing - learning notes 4
- Those configuration parameters of skywalking
- 基于 MATLAB 的圆柱度误差评定方法
- 【异常】异常解决文章格式
- Methods of querying Oracle11g logs, database audit, record troubleshooting
猜你喜欢
OSError: exception: access violation writing 0x0000000000000000
Matlab finite element calculation
2022 Shandong Province safety officer C certificate operation certificate examination questions and answers
Harmonic detection and modeling of three-phase circuit based on GUI and Simulink
不同的ip执行相同的sql脚本会出错吗
[cloud native kubernetes] binary build kubernetes cluster (Part 1) -- deploy etcd cluster and single master
无线定位技术实验一 TDOA-FDOA联合定位
风格迁移篇---SAnet:风格注意网络下的任意风格转换
Restore 360 favorites method after the computer is damaged and the system is reinstalled, put 360sefav_ new_ 2021_ 07_ 16. Favdb files are copied to other computers. Files containing the character new
软件测试—学习笔记4
随机推荐
Fractional PID control and vector control permanent magnet motor
基于MATLAB的无限脉冲响应数字滤波器的设计与仿真
无线定位技术实验一 TDOA-FDOA联合定位
DOM系列之DOM事件
基於 MATLAB 的圓柱度誤差評定方法
小白学习MySQL - Generated Columns功能
The El input input box needs to support multiple inputs
C#入门系列(二十四) -- 密封类和静态类
DOM系列之改变元素内容
源码编译安装LAMP
Simulation of PID tuning method in flow control system
已解决(selenium报错)AttributeError: ‘WebDriver‘ object has no attribute ‘execute_cdp_cmd‘
分布式笔记(04)— 分布式锁之 Redis(分布式锁实现、加锁流程、解锁流程、预防死锁、正确及错误的加解锁实现)
Cylindricity error evaluation method based on MATLAB
Supervisor usage understanding
动环监控模块,动环监控模块分类
OSError: exception: access violation writing 0x0000000000000000
Redis data types and usage scenarios
Filesystem compilation bug record
[cloud native kubernetes] binary build kubernetes cluster (Part 1) -- deploy etcd cluster and single master