Javascript 如何一次从同一个构造函数调用所有对象?

Javascript 如何一次从同一个构造函数调用所有对象?,javascript,object,methods,prototype,Javascript,Object,Methods,Prototype,我是javascript新手。我想一次过滤所有Employee对象,并返回等于或超过300 salary的对象的名称。然后我想将这些结果存储到一个数组中。我不知道如何在所有对象上调用方法filterSalaries()。请帮帮我 var EmployeeBlueprint = { all_info: function () { console.log("Employee: " + this.name + " has a salary of $" + this.salar

我是javascript新手。我想一次过滤所有Employee对象,并返回等于或超过300 salary的对象的名称。然后我想将这些结果存储到一个数组中。我不知道如何在所有对象上调用方法
filterSalaries()
。请帮帮我

var EmployeeBlueprint = {

    all_info: function () {
        console.log("Employee: " + this.name + " has a salary of $" + this.salary + ".");
    },
    isMale: function() { return this.gender == "Male"; },
    isFemale: function() { return this.gender == "Female"; },

    filterSalaries: function() {
        if (this.salary >= 300) {
            return this.name;
        }
    }
};

function Employee (name, salary, gender) {
    this.name = name;
    this.salary = salary;
    this.gender = gender;
};

Employee.prototype = EmployeeBlueprint;

var Matt = new Employee("Matt", 100, "Male");
var Alex = new Employee("Alex", 200, "Male");
var Zack = new Employee("Zack", 300, "Male");
var Mark = new Employee("Mark", 400, "Male");
var Rick = new Employee("Rick", 500, "Male");

首先去掉这些变量并将它们存储在数组中

var emps = [
   new Employee("Matt", 100, "Male"),
   new Employee("Alex", 200, "Male"),
   new Employee("Zack", 300, "Male"),
   new Employee("Mark", 400, "Male"),
   new Employee("Rick", 500, "Male")
];
然后对数组进行
.filter()
处理,以获得简化集和设置为名称的
.map()

var low_salary_names = emps.filter(function(emp) {
    return emp.salary <= 300;
}).map(function(emp) {
    return emp.name;
});
var low\u salary\u names=emp.filter(函数(emp)){

返回emp.salary通常处理此类问题的方法是将所有对象放入一个数组(
var allEmpoyees=[Mark,Alex,…]
),然后过滤该数组以获得结果数组。