**JS類繼承**
~~~
function people(){
var $this = this;
$this.old = "老人";
$this.yang="青年";
$this.number = function(){
return $this.old;
}
}
people.prototype.boy ="男孩";
function student(name,age) {
var $p_this = this;
$p_this.nameS = name;
$p_this.age = age;
$p_this.number = function(){
return getName();
}
function getName(){
return $p_this.nameS;
}
function getAge(){
return $p_this.age;
}
}
student.prototype.sex="男";
student.prototype.number = function(){
console.log("20170101");
}
var stu1 = new student("小馬",21);
var stu2 = new student("小明",30);
console.log(stu1.number());
function extend(student, people) {
var F = function(){};
F.prototype = people.prototype;
student.prototype = new F();
student.prototype.constructor = student;
student.uber = people.prototype;
// student.super = people.prototype;
}
extend(student, people);
var stu1 = new student("小馬",21);
console.log(stu1.number());
console.log(stu1.boy);
~~~
- 各種語言一起擼
- 前言
- 第一章 各種語言類講解對比
- 1.1 基于類的面向對象語言
- 第二章 各種語言面向對象編程
- 2.1 Javascript面向對象編程
- 2.1.1 JS類實現
- 2.1.2 JS類繼承
- 2.2 Object-C面向對象編程
- 2.3 Android面向對象編程
- 2.4 PHP面向對象編程
- 第三章 JS+OC+ADT語言對比
- 3.1 視圖
- 3.1.1 JavaSript創建視圖
- 3.1.2 Object-c創建視圖
- 3.1.2.1 xib視圖視圖創建
- 3.1.3 Andriod創建視圖
- 3.1.3.1 xml視圖創建
- 3.2 事件
- 3.2.1 JavaSript事件綁定
- 3.2.2 Object-c事件代理
- 3.2.2.1 事件代理
- 3.2.3 Andriod事件監聽
- 第四章 PHP服務端語言