为了账号安全,请及时绑定邮箱和手机立即绑定

构造函数为什么不生效?

构造函数为什么不生效?

缥缈止盈 2018-09-14 13:13:12
function Person(name,age,job) {       this.name=name;// 要用构造函数起名时候要首字母大写      this.age=age;    this.job=job;    this.sayName=function () {        alert(this.name);    };}var person3=new Object("Nicholas",29,"Software Engineer");var person4=new Object('Greg',27,"Doctor");console.log(person3.name); // undefinedconsole.log(person3.constructor==Person); //falseconsole.log(person4.constructor==Person); //falseconsole.log(person3 instanceof Object); //trueconsole.log(person3 instanceof Person); //falseconsole.log(person4 instanceof Object); //trueconsole.log(person4 instanceof Person); //false
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 550 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信