//js中prototype实现继承方法一
function Student(){
}
Student.prototype.setName = function(name){
this.name=name;
}
Student.prototype.getName = function(){
return this.name;
}
function SuperStudent(){
}
//js中prototype实现继承
SuperStudent.prototype = Student.prototype;
var superStudent = new SuperStudent();
superStudent.setName("qwe");
alert(superStudent.getName());
//js中prototype实现继承方法二
function extend(json) {
function F () {
}
for(var i in json){//i代表json中的key值,逐个遍历
F.prototype[i] = json[i];//把传进来的json的key 和 value赋给F函数的prototype
}
return F;
}
var Person = extend({
aa:'ad',
b:'asd',
});
var person = new Person();
alert(person.aa);