I am studying a codebase, and I see an object where some methods are declared this way:

Object.assign( className.prototype, {
    method: function () {
        // some var declarations and initializations
        return function method(params) {
            // do stuff
        }
    }
}

Why declaring methods this way? Is it because the code before the "return" gets somehow executed only when the object is declared and the returned function when the method is called?

0 Answers