Why isn't this anonymous function returning?

Brandon

I know this is complete purposeless code I'm just experimenting with anonymous functions with code I have already written and had at hand. I can't figure out though why it array isn't returning?

(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;
}());
T.J. Crowder

...why it array isn't returning?

It is. You're just not doing anything with that return value; see *** comment on first line:

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why isn't this if statement returning the boolean value?

Why isn't my function returning?

Why isn't UIButton returning correct constraints?

Why isn't Main returning?

Why isn't the error array returning when the if statement failed?

Why isn't Yelp returning all of the results?

Why isn't this if statement returning True?

Why isn't setInterval() returning my function's return value?

Javascript Functions in React: why isn't my function returning multiple divs?

Why is my pytest fixture with function scope returning an object that isn't resetting it's class variables in a new test?

Why isn't forEach function letting me returning an object or even just passing it out from the function?

Why isn't Javascript async function immediately returning?

Why can't I use an anonymous function for returning a color value?

Why isn't InputQuery returning bool?

Why isn't shared_ptr implicitly converted to boolean when returning it in a function?

Why isn't this form returning results?

Why isn't my function returning the string?

Why isn't phantomjs returning

My recursive function isn't returning anything

Why isn't it possible to have an anonymous object as argument in a function argument list? C++

Why is Python's Logger Returning Errors When There Isn't An Error?

Why isn't this factorial function returning?

Why isn't main() returning any value?

Why isn't my function returning the correct Key of the values?

Why isn't clear button function isn't working?

Why isn't my output returning as expected?

Why isn't this function returning a value?

Function call isn't returning an output

Why isn't this processing function returning anything related to the string?