zoukankan      html  css  js  c++  java
  • 关于函数的原型对象笔记

       function Person(name,age) {
            this.name = name;
            this.age = age;
        }
        Person.prototype.sayName = function(){
            console.log(this.name);
        }
        let person1 = new Person('lt','18');
        let person2 = new Person('hz','20');
        //一个新的函数都会有一个prototype属性,这个属性指向该函数的原型对象。默认情况下,这个原型对象会有一个constructor属性指回该函数
        console.log(Person.prototype.constructor === Person) //true
        //实例的__proto__属性指向且仅仅指向构造函数的原型对象,实例与构造函数无直接连接关系
        console.log(person1.__proto__ === Person.prototype) //true 
        console.log(Object.getPrototypeOf(person1) === Person.prototype) //true Object.getPrototypeOf() 方法返回实例的__proto__([[prototype]])对象
  • 相关阅读:
    @codeforces
    @codeforces
    @hdu
    @hdu
    @bzoj
    @bzoj
    @topcoder
    推荐系统主题相关资料
    Python统计百分比及排序
    如何发布及部署asp.net网站
  • 原文地址:https://www.cnblogs.com/longsiyuan/p/9777946.html
Copyright © 2011-2022 走看看