• 关于 __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);

  • 相关阅读:
    【算法笔记】多线程斐波那契数列
    RAID技术详解
    Mysql 语句汇总(性能篇)
    JS 网页打印解决方案
    MyEclipse修改
    几个需要学习的点和技术
    MyEclipse配色字体等配置的解决方案
    使用hibernate 分表做增删改查
    Web平台开发流程以及规范
    easyui使用总结
  • 原文地址:https://www.cnblogs.com/river-lee/p/4483709.html
Copyright © 2020-2023  润新知