function Person(name, age) {
this.name = name;
this.age = age;
this.friends = ["hello", "test"];
}
Person.prototype = {
constructor:Person,
sayName: function() {
alert(this.name);
} }
var person1 = new Person("wang", 32);
alert(person1.sayName());
this.name = name;
this.age = age;
this.friends = ["hello", "test"];
}
Person.prototype = {
constructor:Person,
sayName: function() {
alert(this.name);
} }
var person1 = new Person("wang", 32);
alert(person1.sayName());
function Person(name, age) {
this.name = name;
this.age = age;
this.friends = ["hello", "test"];
}
Person.prototype = {
constructor:Person,
sayName: function() {
alert(this.name);
} }
var person1 = new Person("wang", 32);
alert(person1.sayName());//先弹出'wang',再弹出undefined,弹出undefined是因为person的sayName方法没有返回值
person1.sayName();
第二次输出undefined //sayName无返回值,所以alert的结果是undefined