Lập trình

Thực hành lập trình

Dynamic arguments binding with OpenSocial message bundle

1. Problem

- Working with OpenSocial message bundle for localization, sometimes it's necessary to bind dynamic arguments to the message. For example, we have greeting message like this: Hello {user} in which user will be replaced by user's name. But currently with OpenSocial api, we can't. We just can get message bundle by the key without passing any arguments for substitution.

- So this is my approach: using eXo.social.Locale.getMsg(key) the same as prefs.getMsg(key) and eXo.social.Locale.getMsg(key, [val1, val2,...]); for dynamic arguments binding with message bundle.

Multiple event handlers for an element in JavaScript

This afternoon I caught a question posted in phpvietnam group:

"I have an input element with the property onclick="doSomeFunction();". Now I want to add another function, ie onclick="doSomeFunction(); doSomeFunction2();", can I do this with JavaScript? Thanks in advance!" (translated)

Source (in Vietnamese): http://groups.google.com/group/phpvietnam/browse_thread/thread/c7a8688875a320c3

After answering his question, I just want to share my experience when working with JavaScript event handler. I will show you 4 event registration models for the time beings of its use; the way to use context and this keyword in function handler. My approach is that the event object will be passed as 1st parameter to the function handler and this has to refer to the element triggering that event.

Syndicate content