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

Hwk3: cannot set property 'aFunc' of undefined #37

Open
njt2116 opened this issue Feb 23, 2015 · 1 comment
Open

Hwk3: cannot set property 'aFunc' of undefined #37

njt2116 opened this issue Feb 23, 2015 · 1 comment
Labels

Comments

@njt2116
Copy link

njt2116 commented Feb 23, 2015

I am failing on the third test in gulp. I guess i don't understand what Lines 33-35 are testing. It seems to me that we are calling inject on ModuleA with the the result of calling aFunc as the parameter. What is the point of doing this? I think that according to the specs, that if there are no further arguments provided in aFunc, it should just return the value of calling aFunc() back. Why does this seem to be more complicated than this?

The test is to see if we can "load multiple modules." Not sure why adding another module would cause the program to halt. Is it because I am using "this" improperly? It seems that they would be sequential calls. Maybe I am missing an async consideration.

Additionally, should we be using the regex in our register function to parse through the array of dependencies? Or in our inject function? Or both?

@levbrie
Copy link
Contributor

levbrie commented Feb 23, 2015

@njt2116 All really good questions! For the first one, I'm assuming you mean lines 33-5 in lib/di/DI.spec.js. Assuming that's the case:

The point of calling inject with a function that uses aFunc as a parameter is to use the Dependency Injection system to find that function and return a new function that has the aFunc function passed in as an argument. If that sounds like a bit of circular logic, remember that when you use a dependency injection system, you can't just require in other files the way you do in node. Instead, you registered functions and then you use inject to make use of those functions in new functions that you want to create. Because of this, you don't want to simply return the value of call aFunc() since the inject function may want to use aFunc in a variety of ways. What you want to do is give the function that's being injected the ability to make use of aFunc any way it pleases, the same way that when you require in a file or module in node, you want to be able to use that required-in module in any way you please.

As for the "load multiple modules" test, can you make sure to push the latest version of your code so I can see what is going on in there and then send me an email so I can respond privately if necessary, since I really need to be able to see what you're doing right now in order to respond.

Finally, the register function should be extremely simple. It just takes in a name and a function and registers that function under that name in some kind of registeredFuncs object on the module that the register() function is called on. It is only in the inject() function that you need to parse through the array of registered function dependencies. Make sense?

@levbrie levbrie added the hw3 label Feb 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants