一个简单的Extjs继承实现
function extend(sub,sup)
{
//目地:实现只继承父类的原型对象
//1.用一个空函数据中转,目地进行中转
var F = new Function();
//2.实现空函数的的原型对象和超类的原型对象转换
F.prototype = sup.prototype;
//3原型继承
sub.prototype =sup.prototype;
//4.还原子类的构造器
sub.prototype.constructor = sub;
//5.保存父类的原型对象 一方面解耦,另一方面可以方便获得父类的原型对象
sub.superClass = sup.prototype;
}
function People(name,age)
{
this.name = name;
this.age = age;
}
People.prototype=
{
constructor:People,
sayHello:function()
{
alert('hello word')
}
}
function Boy(name,age,sex)
{
//People.call(this,name,age);
Boy.superClass.constructor.call(this,name,age);
this.sex = sex;
}
extend(Boy,People);
People.prototype=
{
sayHello:function()
{
alert('badd')
}
}
var b = new Boy('张三','21','男')
alert(b.name);
alert(b.age);
alert(b.sex);
b.sayHello();
最新文章
- spring mvc 传参数
- js和html5实现画板
- mysql随机获取一条或者多条数据
- 并发容器之CopyOnWriteArrayList(转载)
- HTML增加删除邮件(table)
- selenium webdriver启动Chrome浏览器后无法输入网址的解决办法
- C# 自己定义 implicit和explicit转换
- boke
- Linux入门(17)——Ubuntu16.04显示内存CPU网速等(System Monitor)
- python 识别图片上的数字
- BZOJ4479 : [Jsoi2013]吃货jyy
- 关于springMVC的日志管理
- 配置jboss为windows服务
- mysql学习笔记--数据库操作
- 文件上传和WAF的攻与防
- layui switch 开关监听 弹出确定状态转换
- INTERVAL
- [UE4]嵌套Canvas
- Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge
- GoldenGate 12c + Oracle 12c Multitenant Container databases