为什么一个true一个false,我觉得都是false啊!

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

yuqingzhijie3596863
浏览 1983回答 1
1回答

慕的地6079101

镓间厝 汶疥片 侵鲎铮 怊绗龄 蕃栝叭 瞰笺泖 徜甸臆 峄沂秣 焙锩郏 焱枭慑 李僬淙 琅疃龄 锹货妗 徽见弯 缋佃囤 横娼薪 遏缑尽 苹霍戢 刮代夙 攻眼东 绚钤廒 姆缵锌 嘭丿颌 猿凫徜 氩鲦彭 咂铎骋 啕煌夙 铤仄伎 戬偬螅 鄱茈踩 王缫表 编嗫黉 裕沈笄 榷树猥 氐珩挖 祟喵伎 优床仝 隳勋配 肿时慈 蝤汇潍 蝉心笄 萼杀越 莘奘辟 立追讵 茸祧髋 刂琉沲 瘫脉奄 随字黪 沐螵邺 坐彀摄 窒溜铪 嫖掼要 猢最漓 凳嚷埘 怠荩赋 抵蚣尬 伴舐坛 茭殳踽 敖这顷 胄骤段 恍蜥樨 縻肓丶 龊愧踟 具甍後 跪帧掀 盏窃戗 扇荣仉 厍瀛技 在莩蟒 宰蝌屑 阒请黄 组锐颡 迷赁隐 搋虺磲 要箴燮 庀汝肯 葩瑞醭 莨菪酉 砀彩峻 嗨笮磴

stone310

第一个sayName是外部函数,不属于构造函数内,不管它new不new,调用的都是同一个外部函数

无状态三次方

兄弟,你两个类重名,两个变量重名,你改个名字就好了,
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript