8

I'm wondering if is there a naming convention to namespacing events with AngularJS?

jQuery defines its convention as event.namespace (with namespace at the end, and dot separator)

I've seen some articles (example) where events are named like this: namespace::event (with namespace at the start; and double-colon separator)

Is there a common practice on this subject?

Thanks for your thoughts about it.

1
  • 1
    Yeah I've learned about jQuery event namespacing yesterday while looking for something else in the docs. I find the event.namespace notation a bit odd (I think the namespace should be written before the event it contains) and thus prefer using namespace:event or namespace::event for my Angular events though, I find it much clearer. But never saw any best practices about this, as long as you adopt one and only one convention accross your whole project. Commented Mar 11, 2015 at 11:29

1 Answer 1

1

I haven't heard of anything specific regarding angular, but you should consider that namespacing is a generally good practice for many situations. If you're writing a simple app that won't incorporate other scripts, there isn't much need to namespace. Just consider what could happen in the future of your script's environment (whether event's names could end up clashing) and base your decision on that.

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

3 Comments

Sorry for the delay, thanks for your answer. I've no doubt about the benefits of namespacing and I'm already using it in all of my projects (web or not, with(out) Angular, etc). My questions was more around any convention to prefix these events to avoid conflicts with others libraries. The first part of your answer brings more insights about it.
I just looked around too and didn't find advice to namespace events, which really surprised me. I don't fully agree with @m59 about whether there is need to namespace when not incorporating other scripts. It depends on how big your app is and how many events (and event types) there are. Just like global variables are fine for very small programs, but are bad for larger (i.e. most) programs.
@TylerCollier that's what I said.... "Just consider what could happen in the future". I namespace everything as much as possible in every project.

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.