[英]Why doesn't the following code throw an error when we create a new instance?
class Person {}
let agent = new Person(50);
console.log(agent);
我們沒有在 Person class 上定義constructor
方法, Person
class 也沒有從另一個具有構造方法的 class inherit (extend)
。
如果程序員沒有定義,javascript 中的所有類都有一個默認的構造方法。 在檢查器中試試這個:
class Person {}
console.log(Person);
您將能夠看到默認構造函數 Javascript 適用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.