1

I need to have an object called Map() but it appears there is some function in JavaScript with the same name and when I override it I'm unable to use console (or maybe it's just Opera browser thing). What would be the best way around it? I know I could just use some namespace, but Map is kinda my namespace by itself, so it'd be just too chaotic.

@edit: So I came across this module pattern and I think it may be the best way to use it in my case. Thanks for all the comments anyway.

9
  • 1
    you can override it, if you must... honestly, just change the name of your 'namespace' & don't fuss. Commented Aug 7, 2016 at 23:04
  • 2
    Map is a js type. The best way is to not use the same name. Commented Aug 7, 2016 at 23:05
  • "but Map is kinda my namespace by itself" please stick to the coding conventions in JS. Only classes start with an uppercase letter. Commented Aug 7, 2016 at 23:12
  • 1
    @Martin I think what I use is actually quite similar to that. I do UpperCamelCase for classes (or functions that are meant to be used as constructors) and camelCase properties of objects, but I use lowercase_with_underscores for normal variables, UPPERCASE_WITH_UNDERSCORES for constants (whether they are a property of an object or not), and UpperCamelCase for namespaces (I only ever use one root namespace and properties of that object may also be UpperCamelCase subnamespaces). Commented Aug 7, 2016 at 23:39
  • 1
    @LeszekWiesner, what exactly is your use-case? Maybe you can use a different namespace/name and inject it for example into an IIFE. This way you can use whatever (valid) name you want in your code, and don't have collisions in the global namespace. (function(Map){ /* ... */ })( MyOwnMap ); Commented Aug 7, 2016 at 23:56

1 Answer 1

3

I would say namespace it or create a name other than Map. It's attached to most browser's window object. It would be dangerous to rename it in case it's a dependency of any package your codebase is using.

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

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.