猿问

构造函数为什么不生效?

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


console.log(person3.constructor==Person); //false

console.log(person4.constructor==Person); //false

console.log(person3 instanceof Object); //true

console.log(person3 instanceof Person); //false

console.log(person4 instanceof Object); //true

console.log(person4 instanceof Person); //false


缥缈止盈
浏览 551回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答