zoukankan      html  css  js  c++  java
  • 关于 __proto__和prototype的一些理解

    var Person = function(name) {};

    Person.prototype.say = function() {
    console.log("Person say");
    }

    Person.prototype.age = 20;

    var Man = function() {};
    Man.prototype = new Person();
    Man.prototype.physique = 'strong';

    Man.prototype.age = 25;

    var man = new Man();
    man.say();
    console.log(man.physique)
    console.log(man.age);

    //实例的__proto__ 指向的对象原型prototype
    console.log(man.__proto__ === Man.prototype);
    console.log(man.constructor === Person);
    console.log(man.__proto__.constructor === man.constructor);

    //对象的__proto__指向的都是Function的prototype
    console.log(Person.constructor == Function);
    console.log(Person.__proto__ == Function.prototype);
    console.log(Person.__proto__.constructor == Function);
    console.log(Person.prototype.constructor === Person);
    console.log(Person.prototype.__proto__ === Object.prototype);

    console.log(Function.constructor === Function);
    console.log(Function.prototype.constructor === Function);
    console.log(Function.__proto__.constructor === Function);
    //Function.__proto__ 、 Object.__protot__ 和Function.prototype 指代就是同一个对象funtion
    console.log(Function.prototype===Function.__proto__);
    console.log(Function.prototype===Object.__proto__);

    console.log(Object.prototype.__proto__=== null);
    console.log(Object.__proto__.constructor == Function);

  • 相关阅读:
    PHP导入导出Excel方法
    14款优秀的MySQL客户端
    php接收二进制数据流转换成图片
    PHP中curl_setopt的CURLOPT系列 选项(转)
    二十五个顶级PHP模板
    设计模式——观察者模式 Observer
    设计模式——装饰者模式
    关于JS中的constructor与prototype
    解决JQuery和其他库共存
    json 基础知识
  • 原文地址:https://www.cnblogs.com/river-lee/p/4483709.html
Copyright © 2011-2022 走看看