ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
[TOC] ## 运算符 ``` // 类型判定运算符 print("1" is String); //true if (emp is Person) { // Type check emp.firstName = 'Bob'; } // 缩写 (emp as Person).firstName = 'Bob'; //如果 emp 为null 为报异常 //关系运算符 assert(2 + 3 == 5); assert(2 - 3 == -1); assert(2 * 3 == 6); assert(5 / 2 == 2.5); // 结果是双浮点型 assert(5 ~/ 2 == 2); // 结果是整型 assert(5 % 2 == 1); // 余数 b ??= value; // 如果b为空时,将变量赋值给b,否则,b的值保持不变。 // 条件表达式 var visibility = isPublic ? 'public' : 'private'; ``` ### 级联运算符 实现对同一个对像进行一系列的操 还可以访问同一对象上的字段属性 ``` querySelector('#confirm') // 获取对象。 ..text = 'Confirm' // 调用成员变量。 ..classes.add('important') ..onClick.listen((e) => window.alert('Confirmed!')); ``` 等价于 ``` var button = querySelector('#confirm'); button.text = 'Confirm'; button.classes.add('important'); button.onClick.listen((e) => window.alert('Confirmed!')); ```