zoukankan      html  css  js  c++  java
  • 构造函数模式

     1 function Person(name, age, job) {
     2             this.name = name;
     3             this.age = age;
     4             this.job = job;
     5             this.sayName = function () {
     6                 console.log(this.name);
     7             };
     8         }
     9 
    10         var person1 = new Person("Nicholas", 29, "Software Engineer");
    11         var person2 = new Person("Greg", 27, "Doctor");
    12 
    13         person1.sayName();
    14         person2.sayName();
    15         
    16         console.log(person1.constructor);
    17         console.log(person2.constructor);
    18         console.log(person1 instanceof Object);
    19         console.log(person1 instanceof Person);
    20         console.log(person2 instanceof Object);
    21         console.log(person2 instanceof Person);
  • 相关阅读:
    索引
    mysql事务
    centos 7 gitlab安装服务器
    内网穿透工具 frp使用
    eslint配置
    nodejs连接mongodb(密码)
    插入排序
    直接插入排序
    koa中 log4js使用
    JS中的prototype、__proto__与constructor(图解)
  • 原文地址:https://www.cnblogs.com/qzsonline/p/2400172.html
Copyright © 2011-2022 走看看