f —> Function.prototype —> Object.prototype —> null
2.使用构造器创建的对象
在 JavaScript 中,构造器其实就是一个普通的函数。当使用 new 操作符 来作用这个函数时,它就可以被称为构造方法(构造函数)。
function LuckyStar(){
this.color =[];
this.size =[];}
LuckyStar.prototype ={
addStarColor:function(x){
this.color.push(x);}};
var littleStar = new LuckyStar();
console.log(littleStar.__proto__ === LuckyStar.prototype);
3.使用class关键字创建的对象
"use strict";
class Polygon {constructor(height, width){
this.height = height;
this.width = width;}}
class Square extends Polygon {constructor(sideLength){super(sideLength, sideLength);}
get area(){return this.height * this.width;}
set sideLength(newLength){
this.height = newLength;
this.width = newLength;}}
var square = new Square(2);
4.使用Object.create创建的对象
var a ={a:1};// a ---> Object.prototype ---> null
var b = Object.create(a);// b ---> a ---> Object.prototype ---> null
console.log(b.a);// 1 (继承而来)
var c = Object.create(b);// c ---> b ---> a ---> Object.prototype ---> null
var d = Object.create(null);// d ---> null
console.log(d.hasOwnProperty);// undefined, 因为d没有继承Object.prototype