Declare a function in IIFE

// 
var StateJS;
//  function 
(function (StateJS) {
    var Behavior = (function () {
        // 
        function Behavior(behavior) {
            this.actions = [];
            if (behavior) {
                this.push(behavior); // NOTE: this ensures a copy of the array is made
            }
        }
        // 
        Behavior.prototype.push = function (behavior) {
            Array.prototype.push.apply(this.actions, behavior instanceof Behavior ? behavior.actions : arguments);
            return this;
        };
        /**
         * Tests the Behavior instance to see if any actions have been defined.
         * @method hasActions
         * @returns {boolean} True if there are actions defined within this Behavior instance.
         */
        Behavior.prototype.hasActions = function () {
            return this.actions.length !== 0;
        };     
        Behavior.prototype.invoke = function (message, instance, history) {
            if (history === void 0) { history = false; }
            this.actions.forEach(function (action) { return action(message, instance, history); });
        };
        //  var Behavior = 
        return Behavior;
    })();
    //  StateJS
    StateJS.Behavior = Behavior;
//  StateJS StateJS {}
})(StateJS || (StateJS = {}));

see the above code on the Internet, the above definition constructor can be written in the following form, I have never seen this kind of writing before, who can explain it.
function Behavior (behavior) {

        this.actions = [];
        if (behavior) {
            this.push(behavior); // NOTE: this ensures a copy of the array is made
        }
    }-sharp-sharp-sharp 

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Nov.08,2021

this is written in ES5, using a function to implement the constructor function

Menu