gpt4 book ai didi

vbscript - VBScript 默认属性有问题

转载 作者:行者123 更新时间:2023-12-03 06:18:55 26 4
gpt4 key购买 nike

我阅读了 Eric Lippert 关于 VBScript 中默认属性语义的文章:http://blogs.msdn.com/b/ericlippert/archive/2005/08/30/458051.aspx

它说:

The rule for implementers of IDispatch::Invoke is if all of the following are true:

  • the caller invokes a property
  • the caller passes an argument list
  • the property does not actually take an argument list
  • that property returns an object
  • that object has a default property
  • that default property takes an argument list

then invoke the default property with the argument list. Strange but true.

从表面上看,这似乎是一个奇怪的规则,但当您使用集合时,它是无价的。或者至少是这样,但我似乎无法让它发挥作用。

class Test1
public property get foo
set foo = new Test2
end property
end class

class Test2
public default property get bar (arg)
Response.Write arg
end property
end class

dim t: set t = new Test1
Response.Write TypeName(t.foo) ' => "Test2"
t.foo.bar("Hello, World!") ' => "Hello, World!"
t.foo("Hello, World!") => "Microsoft VBScript runtime error '800a01c2' / Wrong number of arguments or invalid property assignment: 'foo'"

调用者调用 foo 属性并传递参数列表。 foo 属性实际上并不接受参数列表。 foo 属性返回一个 Test2 类型的对象。 Test2 有一个默认属性 bar。该默认属性采用参数列表。

这是一个错误,还是我误解了默认属性语义或我的代码?

最佳答案

好吧,天哪。我本来希望这能起作用。这可能是 VBScript 属性 getter 实现中的一个错误,这将成为我的错。对此感到抱歉。

由于最后一个接触该代码的人是 1998 年的我,因此我不希望很快就会出现修复程序。

关于vbscript - VBScript 默认属性有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5722782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com