我想模擬JavaScript中的多重繼承,所以我需要找到一種方法來獲取兩個JavaScript對象的衝突方法名列表。是否有可能爲兩個對象生成函數名稱列表,然後找到兩個類之間相同的所有函數名稱?在兩個JavaScript對象中查找衝突的方法名
function base1(){
this.printStuff = function(){
return "Implemented by base1";
};
}
function base2(){
this.printStuff = function(){
return "Implemented by base2";
};
}
function getConflictingFunctionNames(object1, object2){
//get a list of conflicting function names between the two objects.
//to be implemented.
}
console.log(getConflictingFunctionNames(base1, base2)); //this should print ["printStuff"]
爲什麼會打印'「object1」,「object2」'? – 2013-03-11 01:50:06
我想我需要獲得每個對象中所有方法的列表,如此處所述,然後找到所有在它們中都相同的方法名稱。 http://stackoverflow.com/questions/2257993/how-to-display-all-methods-in-a-javascript-object – 2013-03-11 01:50:22
@ExplosionPills我修正了這個錯誤。我打算寫'printstuff''。 – 2013-03-11 01:51:12