function Person(){ getAge = function(){ console.log(10); } return this; } Person.getAge = function(){ console.log(20); } Person.prototype.getAge = function(){ console.log(30); } var getAge = function(){ console.log(40); } function getAge(){ console.log(50); } Person.getAge(); // 20 Person的靜態方法 getAge(); // 40 函數的預處理 函數表達式 覆蓋了 函數聲明 Person().getAge(); getAge(); new Person.getAge(); new Person().getAge(); 以下是不太懂的地方,不知道自己的理解是否正確。 Person().getAge(); // 10 普通的函數調用? getAge(); // 不懂為什么輸出10 new Person.getAge(); // 也是Person的靜態方法調用? new Person().getAge(); // 30 // new Person()返回一個Person實例, 沿著原型鏈尋找, 打印30? // Person里本身就有getAge()方法,為什么還會去原型鏈上尋找?
一道前端面試題
慕森王
2019-02-27 14:15:31