日期:2014-05-16 浏览次数:20342 次
function Base() {}
Base.extend = function(obj) {
//第一层构造
var Class = obj['constructor'];
//遍历并给于
for(var i in obj) {
if(i != "constructor") {
Class.prototype[i] = obj[i];
}
}
//提供base方法调用父类的构造
Class.prototype.base = function() {
obj['constructor'].apply(this, arguments)
}
Class.entend = function(objChild) {
var ChildClass = objChild['constructor'];
//遍历并给于
for(var i in objChild) {
if(i != "constructor") {
ChildClass.prototype[i] = objChild[i];
}
}
return ChildClass;
}
return Class;
}
var Person = Base.extend({
constructor: function(name) {
this.name = name;
},
getName : function() {
return this.name;
}
});
var User = Person.extend({
constructor: function(name, password) {
this.base(name);
this.password = password;
},
getPassword : function() {
return this.password;
}
});
var user = new User("Jack", "123");
alert(user.getName())
function Base() { }
Base.extend = function (obj) {
//第一层构造
var Class = obj['constructor'];
//遍历并给于
for (var i in obj) {
if (i != "constructor") {
Class.prototype[i] = obj[i];
}
}
//提供base方法调用父类的构造
Class.prototype.base = function () {
obj['constructor'].apply(this, arguments)
}
//Class.entend//方法名称写错
Class.extend = function (objChild) {
var ChildClass = objChild['constructor'];
//===============================没有添加之类的base方法
//提供base方法调用父类的构造
ChildClass.prototype.base = function () {
&