【转】js 中继承的几种方式
继承的方式一共有三种:
一、原型继承
通过prototype 来实现继承。
function Person(name,age) { this.name=name; this.age=age; } Person.prototype.sayHello=function(){ alert (''使用原型得到Name:'' + this.name); } var per = new Person("马小倩",21); per.sayHello();//输出:使用原型得到Name:马小倩 function Student(){} Student.prototype=new Person("洪如彤",21); //实现原型继承 var stu = new Student(); Student.prototype.grade=5; Student.prototype.intr=function(){ alert(this.grade); } stu.sayHello();//输出:使用原型得到Name:洪如彤 stu.intr();//输出:5
二、构造函数实现继承
function Person(name,age) { this.name=name; this.age=age; } Person.prototype.sayHello=function(){ alert (''使用原型得到Name:'' + this.name); } var per = new Person("马小倩",21); per.sayHello();//输出:使用原型得到Name:马小倩
三、 通过call、apply 实现继承
Azure Service Fabric应用程序日志记录与展现
Azure Web App创建Python应用
AzureWeb App如何做私有仓储的部署
Python web在IIS上发布方法和原理
[转载]DriverStore文件夹特别大,能删除吗?
Azure Web APP中Local Git 如何部署分支
Azure Web 应用如何修改 IIS 配置
文件上传绕过
windows下通过配置服务器安全策略指定IP地址远程访问服务器的设置方法
- 最新文章
-
mysql-luster没有data目录
linq自定义条件Lambda过滤方法
Windbg分析高内存占用问题
Windbg学习笔记
产品-(前后端)开发-测试的见解
分布式架构的总结
.NET 的 WebSocket 开发包比较
C# 进程间通讯
记一发Hive on tez的配置(Hive 3.1.1, Hadoop 3.0.3, Tez 0.9.1)
VMWare Workstation 15 serial number
- 热门文章
-
Docker随笔:Hyper-V PowerShell Module is not available报错解决方法
解决Linux平台下VMware出现"No 3d support is available from the host"或"Hardware graphics acceleration is not available" 错误
installshield12如何改变默认安装目录
SLAX初体验
PyQt5教程——组件 Ⅱ(八)
PyQt5教程——组件(7)
PyQt5教程——对话框(6)
PyQt5——安装Eric6
async和await之我见
Java如何启用Azure Linux虚拟机的诊断设置