Sample interface document - The MDN project 编辑

toolkit/components/cookies/public/nsICookieMonster.idlScriptable A make-believe interface that eats and enjoys cookies. This is an example of what an interface document should look like; however,it's not a document about a real interface. 1.0 66 Introduced Gecko 1.5 Deprecated Gecko 14.0 Obsolete Gecko 20.0 Inherits from: nsICookieFan Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) Note: The article's name should be "nsICookieMonster" but is not in order to make it more obvious this is an example.  Also, you should add the "Interfaces" tag to your article, as well as "Interfaces:Scriptable" if the interface is scriptable.

Implemented by: @mozilla.org/cookie-monster;1. To create an instance, use:

var cookieMonster = Components.classes["@mozilla.org/cookie-monster;1"]
                    .createInstance(Components.interfaces.nsICookieMonster);

Method overview

void eatCookie(in nsICookie cookieToEat);
AString getFunnySaying(in integer number);
void sayYummy(in AString language); Native code only!
void sing();

Attributes

AttributeTypeDescription
favoriteCookieintegerThe cookie monster's favorite kind of cookie. Must be one of the constants defined under Constants on this page.
hungerLevelintegerA value from 0-100 indicating how hungry the cookie monster is. 0 means "stuffed to the brim with cookies" and 100 means "I'm so empty of cookies! Feed me now!"
nameAStringThe cookie monster's name. Read only.

Constants

ConstantValueDescription
COOKIE_FLAVOR_SUGAR1Simple sugar cookie.
COOKIE_FLAVOR_CHOCOLATE_CHIP2Chocolate chip cookie.
COOKIE_FLAVOR_PEANUT_BUTTER3Peanut butter cookie.
COOKIE_FLAVOR_DOUBLE_CHOCOLATE4Chocolate cookie with chocolate chips.
COOKIE_FLAVOR_OTHER0An unknown type of cookie.

Yumminess constants

ConstantValueDescription
COOKIE_NOT_YUMMY1The cookie is disgusting.
COOKIE_SORT_OF_YUMMY2The cookie is good but not awesome.
COOKIE_EXTREMELY_YUMMY3The cookie is really, really yummy.
COOKIE_OMG_YUMMY4OMG THIS IS THE BEST COOKIE EVAR!1!!1.

Methods

eatCookie()

Feeds a cookie to the cookie monster.

void eatCookie(
  in nsICookie cookieToEat
);
Parameters
cookieToEat
The cookie to eat.

getFunnySaying()

Returns a string containing a funny quote the cookie monster might say.

AString getFunnySaying(
  in integer number
);
Parameters
number
The saying number to return.
Return value

An AString containing the requested funny quote. If the specified quote number is invalid, an exception is thrown.

Exceptions thrown
NS_ERROR_FAILURE
Unable to locate the requested quote.
Native code only!

sayYummy

Says something appreciative of the tastiness of the cookie in the specified language.

void sayYummy(
  in AString language
);
Parameters
language
The localization identification indicating the language in which the cookie monster is to express his love of cookies.

sing()

Sings the song "C is For Cookie."

void sing();
Parameters

None.

Remarks

Remember, this isn't a real interface. This is where you would provide additional information about the interface as necessary.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

词条统计

浏览:19 次

字数:7241

最后编辑:7年前

编辑次数:0 次

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