1

In C, if a compiler wants to provide implementation-defined identifiers (language extensions, intrinsics, pseudo-functions and pseudo-macros, basically anything that's not a reserved keyword by the language standard but also isn't a regular function) the convention is for the names to be prefixed with an underscore; it is understood that code should not use such names for normal purposes.

Is there an equivalent convention in JavaScript? Or, if a JavaScript compiler wants to provide implementation-defined identifiers for special purposes, and avoid collisions with identifiers normally used in code, what is the best way for it to do so?

rwallace
  • 31,405
  • 40
  • 123
  • 242
  • Please provide a couple code examples of what you want to do. – jfriend00 Aug 13 '14 at 18:40
  • @jfriend00 A sensible and reasonable suggestion; only thing is, I'm still figuring out the specifics of what I'm trying to do! In particular, I'm trying to figure out how to expose C APIs to JavaScript programs. – rwallace Aug 14 '14 at 18:11

1 Answers1

2

If you review the ECMAScript standards, the language itself uses method names follow this format: [[MethodName]]

However, depending on what you are doing, that alone isn't entirely safe. There is no guarantee that a future version of ECMA Script won't use whatever name you are using. In addition, unless you use the ECMA5 object properties, any properties you add will be enumerable.

Depending on where you are trying to add them, this can be a minor issue or a show stopper.

If you were able to share more details about exactly you wanted to accomplish, we might be better to help more. For instance, name-spacing your new properties might be a better solution.

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • I didn't get from the question that this was about properties. The question refers to "language extensions, intrinsics, pseudo-functions and pseudo-macros" or anything that's not a reserved keyword by the language. I don't think this is property names. – jfriend00 Aug 13 '14 at 18:35
  • @jfriend00 Considering that JS, without extensions, doesn't *have* any of those and thus has no recommended practices, I pointed him to the absolute closest thing I could see as being applicable. – Jeremy J Starcher Aug 13 '14 at 18:37
  • I think that the fact that JS has no recommended practices for such things would have been more of an answer then. Your info just doesn't seem relevant to what was asked. It certainly would have been helpful if the OP provided a couple examples of what they wanted to do. – jfriend00 Aug 13 '14 at 18:40