js 采用delete实现继承示例代码
时间:2023-07-17 09:06:52
//采用对象冒充的方式实现js继承
function A(color) {
this.Acolor = color;
this.AshowColor = function() {
document.writeln("Acolor: " + this.Acolor);
}
}
function B(color, name) {
//将newMethod赋值A,调用A的构造函数
this.newMethod = A;
this.newMethod(color);
//然后删除对A的引用,这样以后不能调用他
delete this.newMethod;
this.Bname = name;
this.BshowName = function() {
document.writeln("Bname: " + this.Bname);
}
}
var objA = new A("red");
objA.AshowColor();
document.writeln("----------------");
var objB = new B("black", "demo");
objB.AshowColor();
objB.BshowName();
document.writeln("----------------");
标签:delete,继承
0
投稿
猜你喜欢
Python的进程,线程和协程实例详解
2021-05-05 04:35:59
MySQL中使用case when 语句实现多条件查询的方法
2024-01-16 17:17:31
Python装饰器用法实例总结
2023-11-18 07:37:36
解决python3 urllib 链接中有中文的问题
2022-10-19 08:43:51
PyTorch中关于tensor.repeat()的使用
2023-06-26 07:13:35
MySQL中易被我们忽略的细节
2024-01-21 09:54:48
如何从IP获知其所在地?
2009-11-15 19:54:00
Python3.5面向对象与继承图文实例详解
2021-05-14 15:48:42
如何修复使用 Python ORM 工具 SQLAlchemy 时的常见陷阱
2022-07-03 20:51:47
Python制作简易计算器功能
2023-05-06 19:53:47
让css使网页图片半透明
2007-02-03 11:39:00
Python网络爬虫信息提取mooc代码实例
2022-01-02 12:18:23
Pandas聚合运算和分组运算的实现示例
2023-11-10 03:49:14
Python多线程操作之互斥锁、递归锁、信号量、事件实例详解
2023-03-09 04:22:05
sysbench对mysql压力测试的详细教程
2024-01-13 01:33:40
python email smtplib模块发送邮件代码实例
2022-05-15 16:37:03
Python实现交通数据可视化的示例代码
2022-03-09 13:00:00
如何在Django中使用聚合的实现示例
2021-08-02 10:32:30
Python3.7实现中控考勤机自动连接
2022-08-07 16:24:22
linux实现定时备份mysql数据库的简单方法
2024-01-16 07:21:57