94-原型面试题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var P=function(){};
P.prototype.aaa=function(){
console.log('ddd');
}
var a=new P();
var b=new P();
b.prototype=P;
b.prototype.aaa=function(){
console.log('ccc');
}
var c=Object.create(null);
var d=new Object();

console.log(P.__proto__ === Function.prototype);
console.log(P.prototype);
console.log(a.__proto__ === P.prototype);
console.log(a.prototype);
console.log(b.prototype);
console.log(c.__proto__);
console.log(d.__proto__ === Object.prototype);

console.log(Number.__proto__);
console.log(Number.prototype);
console.log(Function.__proto__ === Function.prototype);
console.log(Function.prototype);
console.log(Function.prototype.__proto__ === Object.prototype);
console.log(Object.__proto__ === Function.prototype);
console.log(Object.prototype);
console.log(Object.prototype.__proto__);