2

I am having some issues in my production code and I want to be able to send a flag to enable/disable JS logging, so I want to write my own logging function.

I want to use something like function log(){...}. When I looked up reserved words in JS I didn't see log listed, but I do see it listed in the w3schools docs as a math function.

Is it okay to use log() as a function name in production code for IE 7+, Chrome, and FF?

8
  • w3schools is not affiliated with w3c in any way at all, they are an authority on nothing. Commented Jan 7, 2013 at 22:33
  • @WesleyMurch But that doesn't mean anything in the context of the question, their info about Math.log existing is completely valid Commented Jan 7, 2013 at 22:33
  • @JuanMendes: "The w3 docs" as the author states, is misleading. I'm trying to help. Commented Jan 7, 2013 at 22:34
  • @WesleyMurch You're correct, sorry, I didn't notice the OP referred to w3schools documentation as w3 docs I share the same hate for w3 schools that many competent web devs have. Commented Jan 7, 2013 at 22:35
  • @WesleyMurch How does that help in answering the question? Commented Jan 7, 2013 at 22:35

5 Answers 5

3

Yes, it is absolutely fine. The maths log function is a function on the Math object, so will not collide with your implementation.

If you are confused by this sort of thing, look into JavaScript 'namespaces'

How do I declare a namespace in JavaScript?

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

Comments

0

Yes, it is ok. The math log function is available as Math.log, not log so you won't break anything...

Comments

0

That should be fine. The mathematical log function is called via Math.log(x).

Comments

0

Yes it is ok. The math log function always needs to be called as Math.log(). So you're fine.

Comments

-1

I would suggest using an existing object or namespace rather than making your log function global.

See http://www.yuiblog.com/blog/2006/06/01/global-domination/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.