语言范畴定义 java dart kotlin js JavaScript 一般用于HTML 和 Web 的编程语言。
日志打印 Log.e/v/d("%s, %d") print print("I am ${param1}, Hi ${param2},I am ${param3}"); println("$s.length is ${s.length}") 使用 window.alert() 写入警告框 使用 document.write() 写入 HTML 输出 使用 innerHTML 写入 HTML 元素 使用 console.log() 写入浏览器控制台
变量定义 基本类型和object类型定义 var val(final) / var var
final final final final
常量 const const const const(ES2015新增)
顶部基类 Object dynamic Object 无顶部基类: Object Date Array String Number Boolean
判空运算符 if(x==null)null else x (a != null ? a : "b") ?运算符: x?.toString() a ?? "b" ?运算符: var a:Int? var b:Int if(x==null)... 幂运算:**幂
Builder Builder ..运算符 final p = Person() ..username = "lecon" ..password = "123456" ..setSex(true); 构造函数初始化 new Xobject()
接口 implements/interface mixin/with interface class Child : MyInterface implements/interface、abstract
get和set 内部属性设置 setter和getter语法糖 class Rectangle { num left, top, width, height; Rectangle(this.left, this.top, this.width, this.height); num get right => left + width; set right(num value) => left = value - width; num get bottom => top + height; set bottom(num value) => top = value - height; } 内部属性设置 constructor 内部属性设置
异常捕获 try { } catch(e) { } finally { } try { throw FormatException(Expected at least 1 section); } on FormatException catch(e) { print(section exception ${e}); } finally { print("I am finally"); rethrow; } try catch finally try catch finally