1

I have a durandal (basically requirejs) module that starts like this:

define(['plugins/http', 'durandal/app', 'knockout', 'plugins/ajax', 'plugins/formatters', 'durandal/global'], 
function (http, app, ko, ajax, formatters, global) {


//formatters is defined here
        var ctor = function () {

//formatters is not defined here

I put a breakpoint in the debugger and found that formatters is defined outside the function but inside the function it isn't...

Is this unique to requirejs modules? Usually variables declared outside the function can still be accessed in inner functions unless overridden. This seems like some kind of scope problem, but I don't understand what am I missing here - the inner function in within the scope of the outer one, so what's the problem?

Thanks!

1
  • SSCCE please. Commented Jan 2, 2014 at 21:46

2 Answers 2

3

Your problem is likely not that the variable isn't available per se. Add a line like console.log(formatters) inside the ctor function

This will cause the closure to include the formatters variable and thus make it visible to the debugger. Closures only include variables if they are used - at least as far I have seen in Chrome and FF.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, I was starting to question my sanity! It turns out it was there all along... Previously I had a problem with the module not being defined but fixed the issue and now was being driven nuts because it still looked like it wasn't there until I put back the code that uses it!
1

I had this problem before and I managed to work around it by defining a varieble just after the function and assigning it the argument. E.g: Var fmtrs=formaters;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.