With the rapid development of information technology, more and more programming languages are constantly appearing in our lives, while at the same time providing us with more job opportunities. Let's look at the age of programming languages: Lisp (1958), Smalltalk (1972), Objective-c (1984), Haskell (1990), OCaml (1996), and so on. These are the languages of the last century.
This article has selected several of the latest languages: Reason, Swift, Kotlin, Dart as a research object, summed up 10 features:
1 pipe operator Pipeline operator
Reason syntax
Let NewsCore = Me.score |> double |> (IT) + Add (7, it) |> (IT) + boundscore (0, +, it);
The corresponding JavaScript notation:
Boundscore (0, +, add (7, double (Me.score)));
and ES has a corresponding proposal: Tc39/proposal-pipeline-operator
2 pattern matched to the pattern matching
Kotlin syntax
When (x) {in 1..10, print ("x is in the range") validnumbers--Print ("x is valid") !in 10..20-> ; Print ("X is outside the range") else, print ("None of the above")}
3 Reactive (RX) programming build in the language
Dart syntax
Input.onkeydown . Where ((e) = E.ctrlkey && E.code = = ' Enter ') . ForEach ((e) = = Dispatch ( Addtodoaction (E.target.value));
4 default parameters for lambda functions
Kotlin syntax (using it as the default parameter)
Strings . filter{it.length = = 5} . map{it.touppercase ()}
Compare JavaScript
Strings . filter{it = It.length = = 5} . map{it = It.touppercase ()}
5 deconstructed destructuring
Reason Syntax:
Let someints = (ten, twenty) = Someints;type person = {name:string, age:int};let Someperson = {name: ' Guy ', Age:30};let {name, age} = Someperson;
Kotlin syntax
Data class person (Val name:string, Val Age:int) Val (name, age) = person ("guy", 20)
ES6 already has an array deconstruction, ES8 increases the object deconstruction
6 operator Cascade Cascade operator
Dart syntax
Queryselector (' #button ')//Get an object ... Text = ' Confirm '//Use it members ... Classes.add (' important '): Onclick.listen ((e) = Dispatch (Confirmedaction ()));
The corresponding JavaScript notation
var button = queryselector (' #button '); button.text = ' Confirm '; Button.classed.add (' important '); Button.onClick.listen ((e) = Dispatch (Confirmedaction ()));
If you use jQuery basically in the same notation as DART, but the two are fundamentally different
7 IF-expression if expressions
Kotlin syntax
Val result = if (param = = 1) { "one"} else if (param = = 2) { "one"} else { "three"}
For if expressions some people like, some hate, some people feel indifferent; I am very fond of, I have in the previous answer: Https://www.zhihu.com/questio ...
8 Try Expressions
Kotlin syntax
Val result = try { count ()} catch (E:arithmeticex
ception) {throw illegalstateexception (E)
}
9 Automatic Automatic currying
Reason Syntax:
Let add = (x, y) = = x + y; /* Same as (x) = = (y) + x + y; */let five = Add (2,3); /* 5 */let alsofive = Add (2) (3); /* 5 */let addfive = Add (5); /* y = 5 + y; */let Eleven = addfive (6); /* One */let twelve = addfive (7); /* 12 */
10 Methods Extension Method extensions
Swift Syntax:
Extension Int { func repetitions (Task: ()-Void) {for _ in 0..<self { task () } }}3.repetit Ions ({ print ("hello!")}) hello!//hello!//hello!
JavaScript can be extended on the prototype.
I think there's a very useful feature to be given, optional-chaining. It is not mentioned, because most languages already have this feature, it seems that JavaScript development is still a bit slow.
These are the most interesting features of these 10 modern programming languages, and I hope you know something about it.