我一直在使用這樣的構造函數模式:function Class(parameter) { this.id = parameter;}let testOne = new Class('a');let testTwo = new Class('a');console.log(testOne === testTwo);console.log(testOne == testTwo);console.log(testOne.id === testTwo.id);如你所見,我的第一次console.log(testOne === testTwo)回歸false。我認為它與這樣一個事實有關,即new構造對象的不同實例總是彼此不同,即使它具有相同的確切屬性。有沒有另一種方法來檢查兩個對象是否構造具有相同的確切屬性,而不是直接檢查它們的唯一和標識屬性?
確定是否在JavaScript構造函數設計模式中的同一元素上調用構造函數
MYYA
2019-04-24 15:15:06
