没有构造函数的情况下如何在Closure Compiler externs中使用类型 [英] How to have a type in Closure Compiler externs without a constructor

查看:78
本文介绍了没有构造函数的情况下如何在Closure Compiler externs中使用类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为没有构造函数的类型的Google Closure编译器提供外部功能.

I am trying to make externs for the Google Closure Compiler for types that have no constructor.

我尝试了以下操作,但它给了我一个Bad type annotation. Unknown type WindowsMediaActiveX.Cdrom错误,因为没有任何内容告诉编译器WindowsMediaActiveX.Cdrom是类型,而不仅仅是方法/属性的集合.

I have tried the following, but it gives me a Bad type annotation. Unknown type WindowsMediaActiveX.Cdrom error because nothing tells the compiler that WindowsMediaActiveX.Cdrom is a type instead of just a collection of methods/properties.

/**
 * @fileoverview Declares externs for the Windows media player ActiveX control.
 * @author Joshua Dwire
 * @suppress {duplicate}
 */

var WindowsMediaActiveX={};


/**
 * Methods and properties for accessing a CD or DVD in its drive.
 */
WindowsMediaActiveX.Cdrom={};


/**
 * Retrieves the CD or DVD drive letter.
 * @type {string}
 * @readonly
 */
WindowsMediaActiveX.Cdrom.prototype.driveSpecifier;



/**
 * Methods and properties for accessing a collection of CD or DVD drives.
 */
WindowsMediaActiveX.CdromCollection={};


/**
 * Retrieves the Cdrom object associated with a particular drive letter.
 * @param {string} driveSpecifier String containing the drive letter followed by a colon (":") character.
 * @returns {WindowsMediaActiveX.Cdrom}
 */
WindowsMediaActiveX.CdromCollection.prototype.getByDriveSpecifier=function(driveSpecifier){};

我知道我可以改变:

/**
 * Methods and properties for accessing a CD or DVD in its drive.
 */
WindowsMediaActiveX.Cdrom={};

收件人:

/**
 * Methods and properties for accessing a CD or DVD in its drive.
 * @constructor
 */
WindowsMediaActiveX.Cdrom=function(){};

,但是如果我或其他人尝试使用new WindowsMediaActiveX.Cdrom(),则编译器不会显示警告.关于如何定义它的任何想法?

but then the compiler wouldn't show a warning if I or someone else tried to use new WindowsMediaActiveX.Cdrom(). Any ideas on how to define this?

对于那些想要了解更多信息的人,我正在研究一种媒体播放器,它将使用Windows Media ActiveX控件播放媒体.我也在使用Google Closure编译器和库.我需要定义外部播放器以使播放器正常工作,但是ActiveX控件使用的所有类型都没有构造函数.它们都是通过其他方法或通过在html中创建对象来创建的.我应该如何在extern文件中定义它?感谢您的帮助.

For those of you who want more information, I am working on a media player that will use the Windows Media ActiveX Control to play media. I am also using the Google Closure Compiler and Library. I need to define the externs for the player to work correctly, but none of the types used by the ActiveX Control have constructors. They are all created through other methods or through creating an object in the html. How should I define this in the extern file? Thanks for your help.

推荐答案

此模式的典型注释为:

/** @const */
var WindowsMediaActiveX = {};

/**
 * Methods and properties for accessing a CD or DVD in its drive.
 * @constructor
 * @private
 */
WindowsMediaActiveX.Cdrom=function(){};

@private注释表示不打算直接调用构造函数.但是,只有在启用accessControls警告组(带有VERBOSE警告)时,编译器才会报告有关该类型的直接实例化的警告.

The @private annotation is the indication that the constructor is not meant to be directly called. However, the compiler will only report a warning on direct instantiations of the type when the accessControls warning group is enabled (on with VERBOSE warnings).

答案已更新,以将所需的@const批注添加到名称空间.否则,将忽略访问控制注释.

Answer updated to add the required @const annotation to the namespace. The access control annotations will be ignored otherwise.

这篇关于没有构造函数的情况下如何在Closure Compiler externs中使用类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆