277 原型经典题
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>06_原型面试题</title>
</head>
<body>
<script type="text/javascript">
/*
测试题1
*/
function A() {
}
A.prototype.n = 1
var b = new A()
A.prototype = {
n: 2,
m: 3
}
var c = new A()
console.log(b.n, b.m, c.n, c.m) // 1 undefined 2 3
/*
测试题2
*/
function F() {}
Object.prototype.a = function() {
console.log('a()')
}
Function.prototype.b = function() {
console.log('b()')
}
var f = new F()
f.a(); // a()
// f.b() // 报错,f.b is not a function
F.a() // a() ,这里把F看成实例对象
F.b() // b()
console.log(f)
console.log(Object.prototype)
console.log(Function.prototype) // ƒ () { [native code] }
</script>
</body>
</html>
标签:function,console,log,277,原型,经典,var,new,prototype 来源: https://www.cnblogs.com/jianjie/p/12244091.html