设置 CDO.Message 选项时使用的 f(x) = y JScript 习惯用法的 JavaScript 友好替代方案

发布于 2024-07-11 22:35:16 字数 660 浏览 6 评论 0原文

我有一个用 JScript 编写的 ASP 页,它使用 CDO.Message 发送电子邮件。 为了指定 SMTP 服务器(和其他选项),我正在执行以下操作:

mail.Configuration.Fields.Item(
    "http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    "smtp.example.com";

现在,问题来了。 我将此代码放在一个独立的包含文件中,并将其作为 JavaScript 包含在 HTML 页面中,以便我可以在浏览器中对其运行单元测试(使用 JsUnit 等)。 我有 JavaScript 模拟对象(服务器、请求等),它们为包含的 JScript 代码创建模拟 ASP 环境。 我剩下的唯一问题是 CDO.Message 选项设置。 由于上述代码摘录中使用的 f(x) = y 语法不是有效的 JavaScript(无效的左侧操作数),因此我无法在一个浏览器。 目前,我只是在单元测试中使用一个条件来绕过它,以检测环境是否真正是 ASP。

我认为 JavaScript 没有解决方法。 我正在寻找一种替代语法(可能以不同的方式使用 ActiveX 接口)来设置 CDO.Message 选项,该选项在语法上也是有效的 JavaScript。

I have an ASP page written in JScript that sends e-mails using CDO.Message. For specifying an SMTP server (and other options) I'm doing something like this:

mail.Configuration.Fields.Item(
    "http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    "smtp.example.com";

Now, here comes the catch. I have this code in a stand-alone include file that I include in an HTML page as JavaScript so that I can run unit tests against it in a browser (using JsUnit etc.). I have JavaScript mock objects (Server, Request, etc.) that create a mock ASP environment for the included JScript code. The only problem I have left is with the CDO.Message option setting. Since the f(x) = y syntax that's used in the above code excerpt is not valid JavaScript (invalid left-hand operand), I can't run this piece of code (as it is) within a browser. I'm currently simply bypassing it in my unit test with a conditional that detects whether the environment is truly ASP.

I don't think that there's a JavaScript workaround to this. I'm looking for an alternative syntax (that may use the ActiveX interfaces differently) to setting CDO.Message options that would also be syntactically valid JavaScript.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[旋木] 2024-07-18 22:35:16

我在查看 C++ 代码示例时找到了答案 http://msdn.microsoft.com/en-us/library/ms526318(EXCHG.10).aspx

解决方案是显式对 Value 属性进行赋值:

mail.Configuration.Fields.Item(
    "http://schemas.microsoft.com/cdo/configuration/smtpserver").Value =
    "smtp.example.com";

这样,上面的代码就是有效的 JavaScript,可以使用模拟配置对象进行测试。

I figured out the answer when looking at the C++ code example at http://msdn.microsoft.com/en-us/library/ms526318(EXCHG.10).aspx.

The solution is to make the assignment explicitly to the Value property:

mail.Configuration.Fields.Item(
    "http://schemas.microsoft.com/cdo/configuration/smtpserver").Value =
    "smtp.example.com";

This way, the code above is valid JavaScript than can be tested with a mock Configuration object.

二货你真萌 2024-07-18 22:35:16

在为 IIS 编写服务器端 Javascript 时,我也遇到了同样的问题,即 f(x) = y 语法在我的 IDE 语法检查器中失败。 我发现有用的解决方案是 JScript 条件注释,如下所示:

f(x)/*@cc_on@if(0)*/[0]/*@end@*/ = y;

当在 Microsoft 的 JScript 引擎中运行时,它将下标索引 [0] 放在末尾例外。 但是,不可否认,我的解决方案有点hacky。 我认为在大多数情况下你的更干净,所以感谢分享。

-西蒙

I've been having the same problem when writing server-side Javascript for IIS, That f(x) = y syntax was failing in my IDE's syntax checker. The solution I found helpful was JScript conditional comments like so:

f(x)/*@cc_on@if(0)*/[0]/*@end@*/ = y;

It puts the subscript index [0] on the end except when running in Microsoft's JScript engine. But, admittedly my solution is a bit hacky. I think in most cases yours is cleaner, so thanks for sharing it.

-Simon

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