Currently there exists a great deal of confusion when trying to handle local and global users in a virtual wiki because $xcontext.user appears either prefixed or unprefixed with the wiki name from where the user is created.
The convention is that if you are on the wiki where the user belongs to, $xcontext.user is unprefixed, otherwise it's prefixed.
While this sounds good in theory, in practice it's very cumbersome to test (say... know if the current user is a global user or not) just by testing strings and problems can occur when not processing the string correctly.
To fix this, the core class XWikiContext has provided a getUserReference() method that returns a resolved document reference towards the user's profile document that removes ambiguitees.
The only thing left is to expose this method to the web API so that scripts can use it as well.