nsIUUIDGenerator 编辑
xpcom/base/nsIUUIDGenerator.idl
Scriptable This interface can be used to generate an ID that can be considered globally unique, often referred to as a UUID or GUID. 1.0 66 Introduced Gecko 1.8.1 Inherits from: nsISupports
Last changed in Gecko 1.8.1 (Firefox 2 / Thunderbird 2 / SeaMonkey 1.1)Implemented by @mozilla.org/uuid-generator;
as a service:
var uuidGenerator = Components.classes["@mozilla.org/uuid-generator;1"] .getService(Components.interfaces.nsIUUIDGenerator);
Method overview
nsIDPtr generateUUID(); |
void generateUUIDInPlace(in nsNonConstIDPtr id); Native code only! |
Methods
generateUUID()
Obtains a new UUID using appropriate platform-specific methods to obtain a nsID that can be considered to be globally unique.
nsIDPtr generateUUID();
Parameters
None.
Return value
This method returns a nsIDPtr containing a unique ID.
Exceptions thrown
NS_ERROR_FAILURE
- If a UUID cannot be generated (for example if an underlying source of randomness is not available)
generateUUIDInPlace
Obtain a new UUID like the generateUUID()
method, but place it in the provided nsID pointer instead of allocating a new nsID.
void generateUUIDInPlace( in nsNonConstIDPtr id );
Parameters
id
- An existing nsID pointer where the UUID will be stored.
Exceptions thrown
NS_ERROR_FAILURE
- If a UUID cannot be generated (for example if an underlying source of randomness is not available)
Example
Generating a UUID
var uuidGenerator = Components.classes["@mozilla.org/uuid-generator;1"] .getService(Components.interfaces.nsIUUIDGenerator); var uuid = uuidGenerator.generateUUID(); var uuidString = uuid.toString();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论