nsIUUIDGenerator 编辑

xpcom/base/nsIUUIDGenerator.idlScriptable 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)
Native code only!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:70 次

字数:3277

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文