JavaScript-自测题14

1
2
3
4
5
6
7
8
9
10
11
{
Object.prototype.a = 'a';
Function.prototype.a = 'a1';
function Person(){};
var yideng = new Person();
console.log(Person.a);
console.log(yideng.a);
console.log(1..a);
console.log(1.a);
console.log(yideng.__proto__.__proto__.constructor.constructor.constructor);
}

运行结果:

1
2
3
4
5
a1
a
a
Uncaught SyntaxError: Invalid or unexpected token 数据格式错误
ƒ Function() { [native code] }

解析:

  1. Person.a 是function Person()函数,所以结果为:a1
  2. yideng 是 new Person()对象,所以结果为:a
  3. 1..a 是Number(1).a,也是对象,所以结果为:a,特殊转换 +1 1.
  4. 1.a 报错
  5. yideng.__proto__.__proto__.constructor 是Persoon()对象的proto下的constructor 内置函数,结果为:ƒ Function() { [native code] }