三个新秀语言分别在自己的领域统领江湖,但是语法确实非常像,还有一些关键词也挺像,集合在一起做个对比
| Typescript | Dart | Swift | |
|---|---|---|---|
| 变量声明 | let x:string = “ts” let x = “ts” var x = “ts” //不建议用 |
var x = “dart” String x = “dart” |
var x = “dart” |
| 常量声明 | const x:string = “ts” //只有类变量 readonly x:string = “ts” //类和实例都可以用 |
const String x = “dart” //注意dart 中 const 意义相对更复杂 参考 final String x = “dart” |
let x = “dart” //swift中final类似Java,用于子类不可覆盖 |
| 函数声明 | helloWorld(name:string):string | String helloWorld(String name) | func helloWorld(name: String) -> String |
| 匿名函数 | ()=>{} | () {} 或者 ()=>返回变量 | ()->type in code |
| 字符串format | console.log(“hello “+”world “+name) console.log( hello world ${name}) |
print(“hello “ + “world “ +name) print(“hello world $name”) print(“hello world ${ 1 + 1}”) |
print(“hello “ + “world “ +name) print(“hello wolrd \(name)”) |
| 方法引用 | import {} from “” import “” import * as xx from “” |
import “xxx.dart” import “” import “” as xxx; |
import xxx; |
| 基本类型 | 字典 let map = new Map map.set(“lan”,”Typescript”); let lan = map.get(“lan”);//Typescript let map = {“lan”:”Typescript”}; |
字典 var map = Map map[“lan”] = “dart”; var lan = map[“lan”]; var map = {“lan”:”dart”}; |
字典 let map = String:String; map[“lan”] = “Swift”; let lan = map[“lan”]; let map = [“lan”:”Swift”]; |
