One, arrow expression
Used to declare anonymous functions, eliminate the This pointer problem for traditional anonymous functions
A single line can be omitted {}, multiple lines cannot be saved.
var sum = (arg1,arg2) = ARG1+ARG2;
Define a lunch function
var dosomething = () =>{
Console.log ("Hahahha");
}
return even
var array = [1,2,3,4]Console.log (Array.filter (value = = value% 2 = = 0));
, eliminating the this pointer problem for traditional anonymous functions
JavaScript functions
function G
. Expansion InterfaceLike classes, interfaces can be extended. Allows you to be more free to make your interfaces reusable components.
Interface Shape {
color:string;
}
Interface Square extends Shape {
Sidelength:number;
}
var square =
Square.color = "Blue";
Square.sidelength = 10;
Copy CodeAn interface can extend multiple interfaces, creating a combination of all interfaces.
Interface Shape {
color:string;
}
Inte
To see how to implement a linked list with typescript:Class Student {public fullname:string; public next:student; Constructor (public firstname, private middleinitial, public lastname) { This.fullname = FirstName + "" + Middlein Itial + "" + LastName; }} Interface person { firstname:string; lastname:string;} function Greeter (Person:person) { return "Generated javascript:var Student = (function () { function Student (firstname, middleinitial, LastName) {
; Eat (str:string): void;} Class Dog implements animal{ name:string; Constructor (name:string) { this.name=name;} nbsp Eat () { console.log (this.name+ ' eat food ') } Note the following: one. All properties or methods within the interface must be in the implemented class. Two. Interface is the method by which the class implements the interface. 5) Interface extension interface can inherit the interface, with extends implementation. A class can inherit (extends) a class, or an interface can be
TypeScript syntax (1) -- Basic Data Type1. Boolean)
var isDone: boolean = true;
2. Number)
var height: number = 6;
Iii. String type)
You can use double quotation marks or single quotation marks.
var name: string = "bob";name = 'smith';
4. Array)
Two methods to declare an array:
First:
var list:number[] = [1,2,3];
Note:numberIndicates the Data Type of elements in the array,[]Declares an array.
Second:
var list:Array
= [1,2,3];
Note:ArrayDecla
function test () { var gs = new Greeter (' SS '); Alert (Gs.greet ());} Window.onload = Test;class Greeter { greeting:string; Constructor (message:string) { this.greeting = message; } Greet () { return "Hello," + this.greeting; }}Because JSON serialization interaction is often used in the background and foreground, it can be very handy if the background-defined model can be used in the foreground, and smart hints and type checking are also very good features.I
Integration steps:1. Install jquery extremely TS definition fileInstall jquery-install --save-dev @types/jquery2. Page load jquery:" Apps " : [{ ... " Scripts " : [ ".. /node_modules/jquery/dist/jquery.min.js", ], ...}]3. Call the extension method:$ ("selector"). Pluginmethod ();4. Run ng serve:Ng Serve-oThe problem with this is that we're not just trying to call jquery plugin, The TS definition extension of the jquery interface is extended through the plugin d.ts file, and we call jquer
Objective:
With angular practice, for typescript usage Some details of the place is worth to summarize, please follow the small series together to see.
Body:
Find
This.eachname = This.allCount.find (x => x.id = = ID). Index;
Foreach
This.questionTypeSetModels.forEach (
sc => {
this.sum = (number) (This.sum) + (number) (Sc.questiontypescore );
}
)Splice
Removequestiontyperecord (Index): void {
This.disabled.splice (index, 1
From C # to typescript-promise backgroundsI believe that friends who have used JavaScript before have encountered asynchronous callback Hell (callback Hell), n multiple callback nesting not only makes the code read very difficult, maintenance is also very inconvenient.In fact, C # Task before the advent of a similar scenario, the Async Programming mode era, with Action and Func do callbacks are also very popular, but also aware that too many callback
TypeScript into the PitInstallationInstalling with NPMInstall using global modenpm install -g typescriptEditorInstalling the plugin Https://github.com/Microsoft/TypeScript-Sublime-PluginHttps://packagecontrol.io/packages/TypeScriptCompiling using node. js for compilationHello WorldWriting TS filesfunction greeter(person) { return "Hello world!" + person;}let user = "hello world";document.body.innerHTML =
1. Download Webstorm from official website (I am using Webstorm 11.0.2) 2. Install typescript plugin for webstorm, File->setting->plugins, as shown, click Install Jetbrain Plugin button to find first
3. In the pop-up browse jebrains Plugins window, look for the TYPO3, and you will filter out the plugin to be typescript, as shown in:4. Click the Install button on the right to install (I have successfully i
As one of the initiatives to improve JavaScript Application Development, Microsoft recently released TypeScript. This new language is a superset of JavaScript specifications. It adds type checks and static code analysis, and generates native JavaScript. These features are intended to enable developers to benefit from the convenience of Type checks, making it easier to expand JavaScript to support large-scale application development. The existing JavaS
If you try to use CSS Modules in TypeScript the same the same-would use them in JavaScript, with Webpack ' s css-loader, you 'll see an error: "Ts2307:cannot find module './styles.css '". Typings-for-css-modules-loader is a drop-in replacement for Css-loader, works with TypeScript and generates typings fo R CSS on the fly.You'll need to install dependencies first:NPM Install--save-dev css-loader typings-for
times wrong "Sourcemap": true,//for debug, generate the corresponding. map file "Strictnullchecks": false,//in strict null-check mode, null and undefined values are not included in any type, only they are allowed to be assigned with their own and any (with an exception, undefined can be assigned to void). "Target": "ES5",//target code type "paths": {//Module name to List of path mappings based on BaseURL}, "Lib": [//List of library files to be introduced during compilation "Dom",
3.ts function 1) function of the return value and parameters in the definition of the function needs to define its return value can be void, to represent the definition of a function parameter without a return value, for example to analyze the next name:string,age?:number=23 colon is the type of the parameter, add a? Indicates that this parameter is not mandatory, so you can understand it here. If a parameter is written, then it needs to be added, because it is not necessarily transmitted. Using
TypeScript allows-generate definition files for your own libraries. This lesson shows what to organize your project and generate the definition files so it others projects can use your Library with TypeScript.If you ' re writing a library and you want to generate your own definition files, just make sure and add declaration to your Tsconfig:{ "compileroptions": { "RootDir":"src", "Module":"Commonjs", "Target":"ES5", "Noi
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.