[英]JavaScript-friendly alternative to the f(x) = y JScript idiom that's used when setting CDO.Message options
I have an ASP page written in JScript that sends e-mails using CDO.Message. 我有一个用JScript编写的ASP页面,该页面使用CDO.Message发送电子邮件。 For specifying an SMTP server (and other options) I'm doing something like this:
为了指定SMTP服务器(和其他选项),我正在执行以下操作:
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.).
我将此代码包含在一个独立的包含文件中,该文件包含在HTML页面中作为JavaScript,这样我就可以在浏览器中运行它的单元测试(使用JsUnit等)。 I have JavaScript mock objects (Server, Request, etc.) that create a mock ASP environment for the included JScript code.
我有JavaScript模拟对象(服务器,请求等),它们为包含的JScript代码创建模拟ASP环境。 The only problem I have left is with the CDO.Message option setting.
我剩下的唯一问题是CDO.Message选项设置。 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. 由于以上代码摘录中使用的
f(x) = y
语法无效的JavaScript(无效的左手操作数),因此我无法在浏览器中运行这段代码。 I'm currently simply bypassing it in my unit test with a conditional that detects whether the environment is truly ASP. 我目前只是在条件测试中绕过它,并使用一个条件来检测环境是否真正是ASP。
I don't think that there's a JavaScript workaround to this. 我认为没有JavaScript解决方法。 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.
我正在寻找一种替代语法(可能会不同地使用ActiveX接口)来设置CDO.Message选项,这些选项在语法上也将是有效的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 . 在http://msdn.microsoft.com/zh-cn/library/ms526318(EXCHG.10).aspx上查看C ++代码示例时,我找出了答案。
The solution is to make the assignment explicitly to the Value
property: 解决方案是将分配明确地赋给
Value
属性:
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. 这样,上面的代码是有效的JavaScript,可以通过模拟Configuration对象进行测试。
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. 在为IIS编写服务器端Javascript时,我遇到了同样的问题,即
f(x) = y
语法在我的IDE语法检查器中失败。 The solution I found helpful was JScript conditional comments like so: 我发现有用的解决方案是JScript条件注释,如下所示:
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. 除非在Microsoft的JScript引擎中运行, 否则它将下标索引[0]放在最后。 But, admittedly my solution is a bit hacky.
但是,不可否认,我的解决方案有点笨拙。 I think in most cases yours is cleaner, so thanks for sharing it.
我认为在大多数情况下,您的显示器更干净,因此感谢您的分享。
-Simon -Simon
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.