使用现有的对象来提供新创建的对象的__proto__,说句人话就是创造原型的一种方式

    1. var anotherObject = {
    2. name: 'wuhua'
    3. };
    4. var newObject = Object.create(anotherObject, {
    5. age: {
    6. value: 18,
    7. },
    8. });

    image.png
    上面对象的方式实现很流畅,原型也是对象所以也没问题的啦…

    1. function GrandFather() {
    2. }
    3. GrandFather.prototype.name = "grandFather";
    4. GrandFather.prototype.setName = function () {
    5. }
    6. function Son() {
    7. }
    8. var son = Object.create(GrandFather.prototype);

    image.png
    验证对象原型的api
    方式一

    1. Object.getPrototypeOf(对象)

    方式二

    1. 对象.__proto__
    1. function GrandFather() {
    2. }
    3. GrandFather.prototype.name = "grandFather";
    4. GrandFather.prototype.setName = function () {
    5. }
    6. function Son() {
    7. }
    8. var son = Object.create(GrandFather.prototype);
    9. console.log(son.__proto__)
    10. console.log(Object.getPrototypeOf(son))