Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous function expression instead of declaration #43

Open
karolciba opened this issue Oct 16, 2013 · 0 comments
Open

Erroneous function expression instead of declaration #43

karolciba opened this issue Oct 16, 2013 · 0 comments

Comments

@karolciba
Copy link

In the "The Pause That Refreshes: Rebinding and References" chapter, section modules. Where there's:

var DrawModule = (function () {

return {
drawLine: drawLine,
drawRect: drawRect,
drawCircle: drawCircle
}

// public methods
var drawLine = function (screen, leftPoint, rightPoint) { ... }
var drawRect = function (screen, topLeft, bottomRight) { ... }
var drawCircle = function (screen, center, radius) { ... }

// private helpers
function bitBlt (screen, ...) { ... }
function resize (screen, ...) { ... }

})();

which returns

Object { drawLine=undefined, drawRect=undefined, drawCircle=undefined}

should rather be (based on what I've learned in "function declarations"):

var DrawModule = (function () {

return {
drawLine: drawLine,
drawRect: drawRect,
drawCircle: drawCircle
}

// public methods
drawLine = function (screen, leftPoint, rightPoint) { ... }
drawRect = function (screen, topLeft, bottomRight) { ... }
drawCircle = function (screen, center, radius) { ... }

// private helpers
function bitBlt (screen, ...) { ... }
function resize (screen, ...) { ... }

})();

or

var DrawModule = (function () {

// public methods
var drawLine = function (screen, leftPoint, rightPoint) { ... }
var drawRect = function (screen, topLeft, bottomRight) { ... }
var drawCircle = function (screen, center, radius) { ... }

return {
drawLine: drawLine,
drawRect: drawRect,
drawCircle: drawCircle
}

// private helpers
function bitBlt (screen, ...) { ... }
function resize (screen, ...) { ... }

})();

Otherwise module will return POJO with undefined references before executing function expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant