从现在起,不要想过自己学过哪些语言,我现在只学过javascript.
面向对象的实现方法:
传统方法:
var person = {
name:"iwen",
age:30,
eat:function(){
alert("能吃");
}
alert(person.name);
函数构造器方法:
function Person(){
}
Person.prototype = {
name:"iwen",
age:30,
eat:function(){
alert("我在吃");
}
}
var p = new Person();
在javascript中一定要有拟类、构造函数与实例的思想
function People(name){
this._name = name;
}
People.prototype.say = function(){
alert("people_hello"+"this._name");
}
function Student(name){
this._name = name;
}
Student.prototype = new People();//实现继承
var superSay = Student.prototype.say;
Student.prototype.say = function(){
superSay.call(this);
alert("student_hello"+this._name);
}
var s = new Student();
s.say();