【转】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 实现继承
Algs4-1.5.7实现QuickFindUF类和QuickUnionUF类
*Algs4-1.5.6quick-union的运行时间-(未解决)
*Algs4-1.5.5quick-find的运行时间-(未解决)
Algs4-1.5.3使用加权quick-union算法完成练习1.5.1
Algs4-1.5.4给出id[]和sz[]的内容与次数
深入了解RabbitMQ工作原理及简单使用
python 字符串、数字转换为bytes和bytes转换为字符串
django html模板的语法
完美的分布式监控系统——普罗米修斯