function Person(name, age, job){
this.name = name;
this.age = age;
this.job =job;
this.sayName = sayName;
}
function sayName(){
alert(this.name);
}
var person1 = new Person("wo", 29, "software Engineer");
var person2 = new Person("ta", 27, "Doctor");
alert(person1.sayName == person2.sayName); //~~~~~~~~~~~~~~~~~~·true
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Person(name, age, job){
this.name = name;
this.age = age;
this.job = job;
this.sayName = new Function("alert(this.name)"); // 与声明函数在逻辑上是等价的
}
var person1 = new Person("wo", 29, "software Engineer");
var person2 = new Person("ta", 27, "Doctor");
alert(person1.sayName == person2.sayName); //~~~~~~~~~~~~~~~~~~~~~~~~false
慕的地6079101
stone310
无状态三次方
相关分类