JavaScript繼承和構造函數屬性考慮以下代碼。function a() {}function b() {}function c() {}b.prototype = new a();c.prototype = new b();console.log((new a()).constructor);
//a()console.log((new b()).constructor); //a()console.log((new c()).constructor); //a()為什么沒有更新b和c的構造函數?我做錯繼承了嗎?更新構造函數的最佳方法是什么?此外,請考慮以下幾點。console.log(new a() instanceof a); //trueconsole.log(new b() instanceof b); //trueconsole.log(new c() instanceof c); //true鑒于(new c()).constructor等于a()和Object.getPrototypeOf(new c())是a{ },怎么可能instanceof知道這一點new c()是c?http://jsfiddle.net/ezZr5/
JavaScript繼承和構造函數屬性
呼啦一陣風
2019-06-15 17:57:35