原型链
面试题(一):
var F = function() {};
Object.prototype.a = function() {
console.log("aa");
};
Function.prototype.b = function() {
console.log("bb");
};
var f = new F();
F.a(); //aa
F.b(); //bb
f.a(); //aa
f.b(); // 抱错,f.b is not a function
面试题(二):
function A() {
this.name = 'a'
this.color = ['green', 'yellow']
}
function B() {
}
B.prototype = new A()
var b1 = new B()
var b2 = new B()
b1.name = 'change'
b1.color.push('black')
console.log(b2.name) // change
console.log(b2.color) // green yellow black