继承
var inherits = function(sub, parent){
if(Object.create){
sub.prototype = Object.create(parent.prototype, {
constructor: { value: sub, enumerable: false }
});
}else if(sub.prototype.__proto__){
sub.prototype.__proto__ = parent.prototype;
}else{
var clone = function(o){
var F = function(){};
F.prototype = o.prototype;
return new F();
}
sub.prototype = clone(parent);
sub.prototype.constructor = sub;
}
}
function ParentClass(name){
this.name=name;
}
ParentClass.prototype.getName=function(){
return this.name;
}
function SubClass(name,age){
ParentClass.call(this,name);
this.age=age;
}
inherits(SubClass,ParentClass);
这么写的原因很复杂,具体可以看看“也谈JavaScript继承”和“再谈JavaScript继承”
还有继承Array的相关资料http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
GET/SET访问控制器
貌似没有啥好方法,有个资料可以看看http://www.zfkun.com/190.html