JavaScript面向对象编程
发布日期:2021-04-30 21:05:47
浏览次数:125
分类:精选文章
本文共 1111 字,大约阅读时间需要 3 分钟。
JavaScript ??? Class ??
????
? JavaScript ?????????? Object ???????????????????????Object.prototype ???????????
var Student = { name: "studentName", age: 18, run: function() { console.log(this.name + " run..."); }};var xiaoming = { name: "xiaoming"};// xiaoming ???? Studentxiaoming.__proto__ = Student;xiaoming.run(); // xiaoming run...console.log(xiaoming.age); // 18 Class ???ES6?
class ???? ES6 ?????????????????????????
// ???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");xiaoming.hello(); // hellovar xiaohong = new XiaoStudent("xiaohong", 80);xiaohong.myGrade(); // ????? ???
__proto__ ??????????????????? JavaScript ??????????
console.log(xiaoming.__proto__); // ?? Student ??console.log(Student.__proto__); // ?? Object ??
???????????????????????????????
发表评论
最新留言
很好
[***.229.124.182]2026年06月10日 10时41分13秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
R 数据缺失的处理
2023-03-02
php,nginx重启
2023-03-02
php:$_ENV 和 getenv区别
2023-03-02
PHP:PDOStatement::bindValue参数类型php5和php7问题
2023-03-02
Q媒体播放器.如何播放具有多个音频的视频?
2023-03-02
pickle
2023-03-02
Pickle thread.lock(Pymongo)
2023-03-02
pickle模块
2023-03-02
qYKVEtqdDg
2023-03-02
pid控制
2023-03-02
PID控制介绍-ChatGPT4o作答
2023-03-02
PID控制器数字化
2023-03-02
Qwen-VL项目使用指南
2023-03-02
PIESDKDoNet二次开发配置注意事项
2023-03-02
PIGS POJ 1149 网络流
2023-03-02
PIL Image对图像进行点乘,加上常数(等像素操作)
2023-03-02
PIL Image转Pytorch Tensor
2023-03-02
PIL&QOOT;IOERROR:带有大图像的图像文件被截断(&Q)
2023-03-02
PIL.Image、cv2的img、bytes相互转换
2023-03-02