博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript类继承
阅读量:4310 次
发布时间:2019-06-06

本文共 749 字,大约阅读时间需要 2 分钟。

function extend(subClass, superClass) {    var f = function() {};    f.prototype = superClass.prototype;    subClass.prototype = new f();    subClass.superClass = superClass.prototype;}var parent = function (name, age) {    this._name = name;    this._age = age;};parent.prototype.show = function () {    console.info(this._name + " : " + this._age);};var son = function(name,age,height) {    this._height  = height;    son.superClass.constructor.call(this,name,age);};extend(son, parent);//这里没有重写父类也就是parent的show方法son.prototype.show=function() {    console.info(this._name + " : " + this._age+" : "+this._height);};var s1 = new son("jack",12,120);s1.show();var p1 = new parent("father",40);p1.show();

 

转载于:https://www.cnblogs.com/or2-/p/3763368.html

你可能感兴趣的文章
python正则表达式入门二
查看>>
scrapy运行
查看>>
XPATH入门
查看>>
python爬虫 CSS选择器
查看>>
正常关闭java程序
查看>>
查看linux核心数
查看>>
数据结构与算法三: 数组
查看>>
Activiti工作流会签二 启动流程
查看>>
Activiti工作流会签三 撤销,审批,驳回
查看>>
Oauth2方式实现单点登录
查看>>
CountDownLatch源码解析加流程图详解--AQS类注释翻译
查看>>
ES相关度评分
查看>>
我们一起做一个可以商用的springboot脚手架
查看>>
idea在搭建ssm框架时mybatis整合问题 无法找到mapper
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>