var personArray;
createPerson ();
function Person (name, age, gender) {
this.name = name;
this.age = age;
}
Person.prototype.displayPerson = function () {
console.log("Name: " + this.name);
console.log("Age: " + this.age);
};
function createPerson() {
var person = new Person("Max", "24");
console.log(person);
// ERROR: "person.displayPerson is not a function"
console.log(person.displayPerson());
}
在上面的代码段中,在创建函数之前将调用createPerson()
。由于Person构造函数是一个函数声明,因此可以在执行(吊装)时进行访问。但是,为什么这还不适用于person.displayPerson()
?
谢谢!