event namespacing
event namespacing
<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">I really like the notion of event namespacing and currently use it heavily. But I also use closures to define namespaces for my classes like foo.bar.goop = {/**class definitions*/}; What Id like to do is use those namespaces (as strings of course) so I can do stuff like<DIV>jQuery(document).bind("customEvent.foo.bar.goop.MyClass");</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The only reason I cant is because the namespace is currently bound to the event using:</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>// Namespaced event handlers</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>var parts = type.split(".");</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>type = parts[0];</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>handler.type = parts[1];</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>which could be written instead as:</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>// Namespaced event handlers</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>var parts = type.split(".");</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>type = parts.shift();</DIV><DIV><SPAN class="Apple-tab-span" style="white-space:pre"> </SPAN>handler.type = parts.join(".");</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I can obviously work around this by using _ or something else but the change is backward compatible and may provide long term benefits for using these namespaces.</DIV><DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>Chris Thatcher</DIV><DIV>(cell) 202 340 9685</DIV><DIV><A href="mailto:christopher.thatcher@comcast.net">
christopher.thatcher@comcast.net</A></DIV><DIV><A href="mailto:chth@loc.gov">
chth@loc.gov</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN></SPAN></SPAN> </DIV><BR></DIV>