我知道這是完全無意義的代碼我只是用我已經寫好的代碼進行匿名函數試驗。我不明白爲什麼它沒有返回數組?爲什麼不是這個匿名函數返回?
(function() {
function Employee(name, age, pay) {
this.name = name;
this.age = age;
this.pay = pay || 800;
}
function Manager(name, age, pay) {
Employee.call(this, name, age, pay);
this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);
Manager.prototype.addReport = function(report) {
this.reports.push(report);
}
function Cashier(name, age, pay) {
Employee.call(this, name, age, pay);
}
Cashier.prototype = Object.create(Employee.prototype);
var ary = [Cashier, Manager];
return ary;
}());
尋求幫助時,抽出時間來始終如一格式化代碼和可讀性很強將有助於你得到的答案。 *(我這次爲你做了。)* –
數組_is_返回。 – thgaskell
完全同意@ T.J.Crowder。現在,_Anonymous_函數不能被調用,對吧?那麼,你究竟在哪裏檢查他們是否返回一些東西。另外,我想知道使用匿名函數的必要性。對我而言,如果有一種定義函數的標準方式,代碼審查就容易得多。等價物將定義一個命名的函數並在它被定義之後調用它。它不是更清楚嗎? – FDavidov