我知道这是完全无意义的代码我只是用我已经写好的代码进行匿名函数试验。我不明白为什么它没有返回数组?为什么不是这个匿名函数返回?
(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