The process of C # Programmers ' understanding of typescript

Source: Internet
Author: User
Tags constructor export class new features

This article shows you the process of learning typescript from the C # Programmer's point of view, mainly aimed at the similarities and differences between the two languages to carry out a simple contrastive study, I hope to be able to help you.

Brief introduction

Typescript has been developing well, our company in the development of new features, taking into account the maintainability of the program, using the typescript to write the browser program, we are starting from the zero use of typescript, and even I even JavaScript is half a jar, This article describes a C # Programmer's process of understanding typescript.

Note: This writing is based on Typescript0.8 version, and initial use, may be outdated, specific specifications can refer to http://www.typescriptlang.org

Namespaces and classes

As an object-oriented developer, the first thought is how typescript defines a class, and since the principle of our Project Server (C #) is exactly the same as that of the client (typescript) principle, this is exactly what C # is compared to typescript.

C # declaration Class

?

1 2 3 4 Using System; namespace Digiwin.Mars.VirtualUI.Engine {Internal sealed class Decoder {}}

Typescript Declaration Class

?

1 2 3 4 <reference path= ". /collections/icollection.ts '/> Module System.Erp.VirtualUI.Engine {Export class Decoder {}}

First of all, there is a similar concept of namespaces, a call namespace, a module, this is not nonsense.

Second, C # To reference other classes, first you need to refer to the DLL in the project file, and then use a namespace on the header (optional), but in typescript, there is no such concept, directly referencing a file.

C # classes can be public, internal, and many other levels, and sealed and other modifiers, typescript you forget these bar, add export equivalent to public, abstract, value type and so on, this seems not.

But the interface is there.

Methods and comments

Methods of C #

?

1 2 3 4 5 6 7 <summary>///decoding changeset///</summary>///<param name= "Reader" > A changeset Reader object </param> public void D Ecodechangeset (Changerecordreader Reader) {//Decoding context object var ctx = new Decodecontext ();

Typescript declaration method

?

1 2 3 4 5 6 7 8 /** * Passes in the changeset and decodes it into the current object container. * @param {System.Erp.VirtualUI.Engine.IChangeRecordReader} reader-Provides a recordset. */Public Decode (Reader:ichangerecordreader): void {//Decoding context object var ctx = new Decodecontext ();

We first see that C # 's XML document-specific annotations are also supported, unlike the specification that he uses JSDoc.

Normal comments are also used//, and this is exactly the same as JavaScript.

On the declaration of the method, Typescript puts the return parameter behind, and the corresponding type of the argument is placed behind the name, if you declare the variable.

Private _maxid:number; To define a field on a class

var item:virtualobject; Define variables in the method.

On the accessibility of the method, the public is supported so that it can be publicly or not exposed.

Parameters and Construction

In C #, we often define multiple methods with the same name, using different parameter types, but not in JavaScript, so typescript is not allowed.

Because of the above reasons, you can understand that there can only be one constructor. Here is an example of his constructor:

?

1 2 3 4 5 6 7 8 9 10 11 12-13 Constructor (Objectcontainer:virtualobjectcontainer, objectbinder:iobjectbinder) {This._objectContainer = Objec   Tcontainer;   This._binder = Objectbinder; }

Based on the concept of JavaScript, there is no such keyword as ref out in, but there are named ways to access parameters and optional parameters.

I did not find the override keyword, though it was said to have been added after 0.8.

Well, more details will require you to study the specification document slowly, and this document will help you get started and use it happily.

The above mentioned is the entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.