文章关键字 ‘Property Let’

VBS中Property Set和Property Let的区别

2010年10月28日,星期四

说好不玩VBS来着,但是今天有人问我,简单的写一下吧。

对于这个问题,《VBScript Programmers Reference》第215页说的很清楚:

Functionally, Property Let and Property Set procedures do the same thing. However, the Property Set procedure has two differences:

  • It makes it clearer that the property is an object-based property (any technique that makes the intent of the code more explicit is preferable over any other equally correct technique).
  • Code outside of your class must use the Set Object.Property = Object syntax in order to write to the property (also a good thing, because this is the typical way of doing things).

从功能上说,这两者的作用是一样的。但是Property Set有两点不同:第一,它说明了这个属性是一个与对象有关的属性;第二,在类的外面给属性赋值的时候必须使用Set关键字。

文件说明太抽象了,举个例子:

(更多…)