7 kyu
Javascript Namespacing
2,218 of 2,288arlaneenalra
Loading description...
Object-oriented Programming
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Creating class like that feels kinda wierd tbh.
Hi, I've added a CoffeeScript translation, if you want to approve it, instructions for the approval process are here.
You say in the assignment: "It should also have a function named sayHello that returns the string passed into the constructor." You should be more specific with what you mean by "It". Please try to rephrase the sentence.
There is actually no such thing as a "namespace" in Javascript. Therefore, the description needs to explain how to create something that acts like a namespace in Javascript, or it needs to at least provide a link to additional information.
You shouldn't just expect us to have to Google it and figure it out.
If that namespace weren't pre-defined, I wouldn't had to google for, and learn about them at all. So, I guess... Thanks for introducing me namespaces!
Hey bro, the existing 'MyNamespace' really hit me...
This comment has been hidden.
Got it!
I need to be able to add the constructor to an existing namespace, without clobbering any existing object called
MyNamespace.MyClass
. My code in my question didn't do that.You should provide some reference about namespace for a beginner kata.
This comment has been hidden.
Your solution is overwriting the namespace if it doesn't exist or doning nothing if it does. You need to create the namespace if it doesn't exist and always add the MyClass stuff.
The example in the description says "var phrase = myObject.sayHello(); // phrase should be 'Hello!'".
Because of the naming I believed that the sayHello function should always output "Hello!" and was wondering why it was specified that the constructor must accept a string. This lead to my solution failing because the test cases were looking for just "hello".
Am I now correct in understanding that sayHello should return the string passed to the constructor and not "hello"?
Whatever it's worth, reading the instructions, I didn't realize that the namespace already existed. I had to read through all the discussion posts to figure it out.
Yes, it's a bit confusing since it says "inside a namespace MyNamespace", imo it should say "inside the namespace". Also the comment says "Define MyNamespace". Finally saying "class" and "namespace" could confuse people who comes from other OOP languages..
The first line of the Kata says "Define a class named MyClass inside a namespace MyNamespace." If I hadn't ready your comment I may have never figured this out. Thanks!
Yes, agreed!
Yep. The existing 'MyNamespace' nailed me too. Probably should explicitly say in the description that the namespace already existed.
That being said, I really hadn't messed with JavaScript namespaces at all prior to this kata, so... OS!!!!
javascript doesn't support classes! So the requirement is a little misleading...
I made the same mistake for the longest time: MyNameSpace vs. MyNamespace.....I wonder if the MyNameSpace could be changed to something less likely to cause confusion. Although, I understand that the MyNamespace is the correct capitalization since Name and Space aren't separate words.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
arlaneenalra: Hahaha - oh wow, you're right - facepalm and doh initiated :)
GuardianGI: thanks for your suggestions also, I would have been surprised if the !function(){}() format hadn't worked, it's fairly common (and valid) JS for the module pattern (although JSLint will complain!) but I'm grateful for you taking the time :)
it would have helped A LOT if the description dais the namespace is already defined and should not be overwritten entirely....
That description does seem a little ambiguous, I've adjusted the documentation.
Another small improvement could be to use more meaningful names, for example:
Define a class named Doorman inside a namespace MyHotel. The class constructor should accept a single
greeting
string argument. It should also have a function named sayHello that returns the greeting passed into the constructor.That's actually a good idea, but implementing it would break all the current solutions. Hmm, I'll have to think about it little before make a change like that.
The final test case was stumping me because the description doesn't say anything MyNamespace already being defined.
Also this:
would read better as this:
Ya know, I just wrote that and I have no idea how I messed it up so badly, fixed!
Yep, if there's going to be a test case that fails a solution if it overwrites the existing MyNamespace namespace, then the directions can't say that you get 'bonus points' for not overwriting it -- they need to clearly state that you MUST NOT overwrite a potentially-existing namespace.
I think the description can be adjusted some more. It would be clearer to say up front that the namespace may or may not exist yet. And that the MyClass functionality should be supported in both cases.