原型对象与原型链
程序员文章站
2022-04-24 23:13:53
...
知道类和继承,理解起来不难,多去敲敲。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<span>sssss</span>
<script type="text/javascript">
console.log(Number);
console.log(typeof Number);//function
console.log(Number.prototype);//Number {constructor: function, toExponential: function, toFixed: function, toPrecision: function, toString: function…
console.log(Object);//function Object() { [native code] }
console.log(Object.prototype);
console.log('-------------字面量对象');
var a = {};
console.log(a);//
console.log(a.prototype);//undefined
console.log(Object.prototype);//同下
console.log(a.__proto__); //同上Object {__defineGetter__: function, __defineSetter__: function, hasOwnProperty: function, __lookupGetter__: function, __lookupSetter__: function…}
console.log('------------------构造函数');
var person = function(){
this.name = '小明';
this.show = function(){
};
};
var stu = new person();
console.log(Function.prototype);
console.log(person.__proto__);//function () { [native code] }
console.log(person.prototype);//object{constructor:function,__proto__:object}
console.log(stu.prototype);//undefined 只有函数是有prototype
console.log(stu.__proto__);//同上上
console.log(stu);
console.log('--------------小实例');
Object.prototype.show = function(){
console.log('我给自己添加了一个show方法');
this.author = '高亚丽';
}
var b = {};
b.show(); //我给自己添加了一个show方法
console.log(b.author);//高亚丽
console.log(Object.prototype);
</script>
</body>
</html>
我的图解: