function Fun(){
var val = 1;
var arr = [1];
function fun(){}
this.val = 1;
this.arr = [1];
this.fun = function(){};
}
Fun.prototype.val = 1;
Fun.prototype.arr = [1];
Fun.prototype.fun = function(){};
console.log("--------------------");
function Super(){
this.val = 1;
this.arr = [1];
}
function Sub(){
}
Sub.prototype = new Super();
var sub1 = new Sub();
var sub2 = new Sub();
sub1.val = 2;
sub1.arr.push(2);
console.log(sub1.val);
console.log(sub2.val);
console.log(sub1.arr);
console.log(sub2.arr);
console.log(Sub.constructor, Sub.prototype.constructor);
console.log("--------------------");
function Super(val){
this.val = val;
this.arr = [1];
this.fun = function(){
}
}
function Sub(val){
Super.call(this, val);
}
var sub1 = new Sub(1);
var sub2 = new Sub(2);
sub1.arr.push(2);
console.log(sub1.val);
console.log(sub2.val);
console.log(sub1.arr);
console.log(sub2.arr);
console.log(sub1.fun === sub2.fun);
console.log("--------------------");
function Super(){
this.val = 1;
this.arr = [1];
}
Super.prototype.fun1 = function(){};
Super.prototype.fun2 = function(){};
function Sub(){
Super.call(this);
}
Sub.prototype = new Super();
var sub1 = new Sub(1);
var sub2 = new Sub(2);
console.log(sub1.fun === sub2.fun);
console.log(Sub.prototype.constructor);
console.log("--------------------");
function beget(obj){
var F = function(){};
F.prototype = obj;
return new F();
}
function Super(){
this.val = 1;
this.arr = [1];
}
Super.prototype.fun1 = function(){};
Super.prototype.fun2 = function(){};
function Sub(){
Super.call(this);
}
var proto = beget(Super.prototype);
proto.constructor = Sub;
Sub.prototype = proto;
var sub = new Sub();
console.log(sub.val);
console.log(sub.arr);
console.log("--------------------");