define(["dojo/_base/declare"], function (declare) {
// module:
// StyleNames
// summary:
// Style element names.
var StyleNames = declare(null,
{
PROP1: "Style1",
PROP2: "Style2"
}
);
StyleNames.dataContexts = [
StyleNames.PROP1,
StyleNames.PROP2,
];
return StyleNames;
});
var styleNames = new StyleNames();
console.log("PROP1 is defined as: ", styleNames.PROP1); // prints "Style1"
console.log("dataContexts is undefined: ", styleNames.dataContexts); // Error: styleNames.dataContexts is undefined
我的设置类似于https://stackoverflow.com/a/11329956/1610451但查看 DOM,我可以看到它设置为styleNames.constructor.dataContexts
具有未定义值的构造函数。
背景故事:我正在将 ActionScript 代码移植到 JavaScript,并且需要维护现有接口。我要移植的 ActionScript 代码示例是:
public class StyleNames {
public static const PROP1 : String = "Style1";
public static const PROP2 : String = "Style2";
public static const dataContexts : Array = [
PROP1,
PROP2
];
public function StyleNames(){}
}