我知道这是完全没用的代码我只是尝试使用我已经编写过的代码的匿名函数。我无法弄清楚为什么数组没有返回?
(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;
}());
答案 0 :(得分:1)
...为什么数组没有返回?
是的。你只是没有做任何有回报价值的事情;请参阅第一行***
评论:
var result = (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;
}());
console.log(result);
答案 1 :(得分:1)