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);

  • 相关阅读:
    【转】GitHub 中国区前 100 名到底是什么样的人?
    不同服务器数据库之间的数据操作
    行列互换
    千万级数据查询
    用命令对sql进行备份
    通过SQL Server 2008数据库复制实现数据库同步备份
    各种字符串合并处理示例.
    字符串分解
    四大排序函数
    cross apply 和 outer apply
  • 原文地址:https://www.cnblogs.com/river-lee/p/4483709.html
Copyright © 2011-2022 走看看