// Options: --annotations --array-comprehension --async-functions --debug --debug-names --exponentiation --free-variable-checker --generator-comprehension --low-resolution-source-map --input-source-map --member-variables --module-name --referrer --require --script --symbols --types --validate
//annotation class
class Template{
value:string;
constructor(value:string){
this.value = value;
}
}
//annotation class
class Attribute{}
@Template('<div>xxx</div>')
class SomeEl{
@Attribute counter:int=0;
constructor(){}
}
(function main(){
console.log(SomeEl.annotations);
console.log(SomeEl.properties); //prints undefined
})();如何访问atscript中的字段注释?我只能访问类注释,但不能在类中使用字段注释,希望您能提供帮助。
上面的代码被转换成
$traceurRuntime.options.symbols = true;
var Template = function Template(value) {
"use strict";
this.value = value;
};
($traceurRuntime.createClass)(Template, {}, {});
Object.defineProperty(Template, "parameters", {get: function() {
return [[$traceurRuntime.type.string]];
}});
var Attribute = function Attribute() {
"use strict";
};
($traceurRuntime.createClass)(Attribute, {}, {});
var SomeEl = function SomeEl() {
"use strict";
this.counter = 0;
};
($traceurRuntime.createClass)(SomeEl, {}, {});
Object.defineProperty(SomeEl, "annotations", {get: function() {
return [new Template('<div>xxx</div>')];
}});
(function main() {
console.log(SomeEl.annotations);
console.log(SomeEl.properties);
})();我看不出被认为是归档counter的counter注释
发布于 2015-02-02 13:56:22
这里有几处出错,构造函数上的注释与类上的注释相同。
@Template('<div>xxx</div>')
class SomeEl{
@Attribute
constructor(){}
}上述内容转化为:
Object.defineProperty(SomeEl, "annotations", {get: function() {
return [new Template('<div>xxx</div>'), new Attribute];
}});注意,构造函数上的注释与类上的注释相同。任何其他函数上的注释都会将注释放在该函数上,但构造函数和类本质上是相同的。
new Attribute没有出现在注释中的原因很可能是counter: int和分号(;)。您混淆了AtScript的另一个概念,即参数注释。这些是这样写的:
@Template('<div>xxx</div>')
class SomeEl{
constructor(counter: int){}
}这转化为以下几点,这就是我相信你想要的:
var SomeEl = function SomeEl(counter) {};
($traceurRuntime.createClass)(SomeEl, {}, {});
Object.defineProperty(SomeEl, "annotations", {get: function() {
return [new Template('<div>xxx</div>')];
}});
Object.defineProperty(SomeEl, "parameters", {get: function() {
return [[int]];
}});
return {};https://stackoverflow.com/questions/28264922
复制相似问题