Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

javascript - What does the @ (at sign) mean in the latest TypeScript (presumably v1.5) example?

There is a very interesting picture was posted in the official TypeScript blog.

Wierd syntax

I wonder what the @ (at sign) symbol is doing there since (as far as I know) it cannot be used in JavaScript identifiers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The big news this week is the merging of AtScript and TypeScript.

The following example from the AtScript documentation...

@Component()
class MyApp {
  server:Server;
  @Bind('name') name:string;
  @Event('foo') fooFn:Function;
  @Inject()
  constructor(@parent server:Server) {}
  greet():string {}
}

Compiles into the following JavaScript...

function MyApp() {}
MyApp.properties = {
  'server': { is: Server },
  'name': { is:string,
            annotate: [new Bind('name']},
  'fooFn': { is:Function,
             annotate:[new Event('foo')]}
}
MyApp.annotate = [
  new Component(),
  new Inject()
];
MyApp.parameters = [
  {is:Server, annotate:[parent]}
];
MyApp.prototype.greet = function() {}
MyApp.prototype.greet.returns = string;

AtScript was planned to be a layer on top of TypeScript (i.e. a super-set of a super-set) - but now the two projects are one.

Annotations are described thus:

  • AtScript annotation syntax is just a shorthand of placing the same information in ES5. It would be reasonable for an ES5 developer to write these annotations manually. A helper library could even be provided.
  • Annotations can only be placed on functions.

  • An annotation placed on a class is an annotation placed on the class’ constructor function.

  • An annotation placed on a field gets moved to the constructor function.

  • All annotations are translated as properties on a function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...