【转】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 实现继承
linux下 tar解压 gz解压 bz2等各种解压文件使用方法
linux性能检测工具
firefox的plugin-container进程关闭方法
部署额外域控制器,Active Directory
利用yum下载软件包的三种方法
HP iLo2 试用序列号
(转)Linux下root密码丢失和运行级别错误的解决办法
linux下的5个查找命令
(转)CentOs上配置samba服务