【转】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 实现继承
C语言基本用算
C语言的scanf函数
C语言一些知识点总结
C语言程序
House Robber 分类: leetcode 算法 2015-07-09 20:53 2人阅读 评论(0) 收藏
[leetcode] Reverse Linked List 分类: leetcode 算法 2015-07-09 18:44 2人阅读 评论(0) 收藏
合并k个已排序的链表 分类: leetcode 算法 2015-07-09 17:43 3人阅读 评论(0) 收藏
[leetcode] Reverse Linked List
Merge k Sorted Lists
- 最新文章
-
object -c OOP , 源码组织 ,Foundation 框架 详解1
Objective
Compiler 1.6.5 —1.6.7
13 Red-black Trees
12. binary search Trees
11 Hash tables
10.3 Implementing pointers and objects and 10.4 Representing rooted trees
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32
(转)iOS学习之 plist文件的读写
(转)Objective-C中的instancetype和id区别