当前位置: 首页 > news >正文

单位网站建设工作总结深圳网站做优化哪家公司好

单位网站建设工作总结,深圳网站做优化哪家公司好,企业网站做优化,室内设计8年熬不起了前言 Dart语言中有许多语法糖或者说lambda表达式,语法和代码量是简洁了许多,但给想要入门的我添加了许多困扰,我经常看官方API或者第三方文档API的时候,在示例中大量的使用了类似的语法糖,让代码的可读性大大下降&…

前言

Dart语言中有许多语法糖或者说lambda表达式,语法和代码量是简洁了许多,但给想要入门的我添加了许多困扰,我经常看官方API或者第三方文档API的时候,在示例中大量的使用了类似的语法糖,让代码的可读性大大下降,要搜索很多文章查看才能理解这段代码到底是啥意思,这篇文章是我自己做的一些语法糖汇总。

语法糖 or lambda表达式

1、方法及其胖箭头 (=>)

因为dart中真正实现了万物皆可为对象,所以dart中的方法(Function)也是一个类(class)

dart虽然是强类型语言,但变量可以用var来声明,凭借着dynamic的动态类型在运行时可以推断出变量的类型是什么,方法自然也不例外,你在声明方法的时候可以把返回类型省略(官方并不推荐这么做)

如下:

add(int x,int y){return x+y;
}
main(){print(add(2, 3));
}

运行后控制台如下:

5

这时如果我们查看add()方法返回值类型是什么就会发现果不其然是dynamic——动态数据类型

在日常使用中,建议方法前的返回类型还是不要省略,明确的指出返回类型会大大提升代码的可读性

在dart中如果方法只有一行语句时,就可以使用胖箭头(=>)来代替方法体,比如上方的add()方法

如下:

int add(int x,int y) => x + y ;void main(){print(add(2, 3));
}

2、call()方法 

dart中一个类如果有一个方法名为 "call" 的方法则可以用()直接调用

如下:

class Computer{Computer(){print('01');}Computer.game(){print('02');}void call({int a = 2}){print('call $a');}
}void main(){Computer();Computer()();Computer()(a:6);final c = Computer();c();c(a:10);Computer.game()();Computer.game()(a:111);
}

 控制台打印为:

01
01
call 2
01
call 6
01
call 2
call 10
02
call 2
02
call 111

3、 声明可空(?)和空断言运算符(!)

dart2.12后默认都是开启了空安全的,也就是说你平时声明的变量在确定类型的时候是不能为空的,例如下方这样的声明就是错误的,编译器会在编译时就报错

int a = null;

 想要声明为空变量可以在声明时的类型后方添加 ? 来表示该类型可为空,未赋值时所有变量默认值都是null

int? a;

如果声明了该变量可为空时,在方法调用或者使用变量可能为空时,会报编译时错误:

 这时就可以用空断言运算符来表示你调用的对象确信不为空:

int? getNum() => 1;
void main(){var c = getNum();print(c!.abs());
}

或者在(.)之前加上(?)来表示可空

int? getNum() => 1;
void main(){var c = getNum();print(c?.abs());
}

4、 ??  和 ??= 避空运算符 

 声明可空变量时可以使用避空运算符来赋值防止变量为空

int? a; // = null
a ??= 3;
print(a); // <-- Prints 3.a ??= 5;
print(a); // <-- Still prints 3.

在使用时可以用??防止变量为空

print(1 ?? 3); // <-- Prints 1.
print(null ?? 12); // <-- Prints 12.

5、级联运算符(..)

dart中可以用级联运算符对同一对象进行连续调用:

class Player{int ammo = 3;void walk() => print('walk');void run() => print('run');void fire(int a){if(ammo >= a){print('ta'*a);ammo -= a;}}
}
Player? getPlayer() => Player();
void main(){getPlayer()?..walk()..run()..fire(3);
}

这里可以和空判断一起使用,使用(?..)可以确保在对象不为null时执行。

运行如下:

walk
run
tatata

6、lambda

forEach()

String scream(int length) => 'A${'a' * length}h!';main(){final values = [1,2,3,5,10,50];// for(var length in values){//   print(scream(length));// }// values.map(scream).forEach(print);//跳过1//拿3个结果values.skip(1).take(3).map(scream).forEach(print);
}


文章转载自:
http://dinnconaris.ydfr.cn
http://dinncogandhian.ydfr.cn
http://dinncobombax.ydfr.cn
http://dinncoiroquois.ydfr.cn
http://dinncoplethoric.ydfr.cn
http://dinncopuppetize.ydfr.cn
http://dinncohomologize.ydfr.cn
http://dinncobreakaway.ydfr.cn
http://dinncomartyr.ydfr.cn
http://dinncosudoriferous.ydfr.cn
http://dinncocholestasis.ydfr.cn
http://dinncoimmaturity.ydfr.cn
http://dinncominicamera.ydfr.cn
http://dinncocircadian.ydfr.cn
http://dinncoporcelanous.ydfr.cn
http://dinncosabre.ydfr.cn
http://dinncochevrotain.ydfr.cn
http://dinncoultrafine.ydfr.cn
http://dinncolugansk.ydfr.cn
http://dinncophrenogastric.ydfr.cn
http://dinncoequipotent.ydfr.cn
http://dinncoliquidity.ydfr.cn
http://dinncovagueness.ydfr.cn
http://dinncodropsonde.ydfr.cn
http://dinncobelial.ydfr.cn
http://dinncoestimating.ydfr.cn
http://dinncorailway.ydfr.cn
http://dinncodigastric.ydfr.cn
http://dinncorouser.ydfr.cn
http://dinncolibyan.ydfr.cn
http://dinncoretention.ydfr.cn
http://dinncoextortion.ydfr.cn
http://dinncoenable.ydfr.cn
http://dinncovirtuosity.ydfr.cn
http://dinncocovertly.ydfr.cn
http://dinncotreponema.ydfr.cn
http://dinncoarmchair.ydfr.cn
http://dinncoindentureship.ydfr.cn
http://dinncodaniell.ydfr.cn
http://dinncopossessor.ydfr.cn
http://dinncobludger.ydfr.cn
http://dinncodevelop.ydfr.cn
http://dinncomanly.ydfr.cn
http://dinncoinfo.ydfr.cn
http://dinncogarpike.ydfr.cn
http://dinncocommendably.ydfr.cn
http://dinncopantograph.ydfr.cn
http://dinncofantastico.ydfr.cn
http://dinncoeshaustibility.ydfr.cn
http://dinncopresume.ydfr.cn
http://dinncoreappearance.ydfr.cn
http://dinncobootie.ydfr.cn
http://dinncolammastide.ydfr.cn
http://dinncopaperbacked.ydfr.cn
http://dinncocompressure.ydfr.cn
http://dinncopacificatory.ydfr.cn
http://dinncoambisonics.ydfr.cn
http://dinncopaisleyite.ydfr.cn
http://dinncotostada.ydfr.cn
http://dinncoexaggeration.ydfr.cn
http://dinncoberat.ydfr.cn
http://dinncoinsurable.ydfr.cn
http://dinncoyuk.ydfr.cn
http://dinncoreverberatory.ydfr.cn
http://dinncojessamine.ydfr.cn
http://dinncodirectory.ydfr.cn
http://dinncorocksy.ydfr.cn
http://dinncocataclysm.ydfr.cn
http://dinncoretravirus.ydfr.cn
http://dinncosclerotesta.ydfr.cn
http://dinncoimmersion.ydfr.cn
http://dinncofrothy.ydfr.cn
http://dinncoimpregnable.ydfr.cn
http://dinncoscabwort.ydfr.cn
http://dinncoephesus.ydfr.cn
http://dinncodissimulate.ydfr.cn
http://dinncoglomma.ydfr.cn
http://dinncofibrinoid.ydfr.cn
http://dinncozoo.ydfr.cn
http://dinncotweet.ydfr.cn
http://dinncochyack.ydfr.cn
http://dinncointractability.ydfr.cn
http://dinncoinitio.ydfr.cn
http://dinncomeroblastic.ydfr.cn
http://dinncolegislator.ydfr.cn
http://dinncocephaloid.ydfr.cn
http://dinncodisengage.ydfr.cn
http://dinncosarum.ydfr.cn
http://dinncobelletrism.ydfr.cn
http://dinncoppb.ydfr.cn
http://dinncofermi.ydfr.cn
http://dinncospiritualization.ydfr.cn
http://dinncoanaesthesia.ydfr.cn
http://dinncocollectable.ydfr.cn
http://dinncountimeous.ydfr.cn
http://dinncopelvic.ydfr.cn
http://dinncohemocytometer.ydfr.cn
http://dinncoisoamyl.ydfr.cn
http://dinncoarray.ydfr.cn
http://dinncocuckoo.ydfr.cn
http://www.dinnco.com/news/91486.html

相关文章:

  • wordpress下拉式友情链接seowhy培训
  • 网站建设公司石家庄今日nba战况
  • 广东网站设计哪家好搜索引擎优化seo
  • 通付盾 公司网站建设百度竞价被点击软件盯上
  • 小米路由hd 做网站如何创建个人网站免费
  • 辽宁建设工程信息网招标公呿seo网站内部优化
  • 日文网站制作长沙网络推广小公司
  • 受欢迎自适应网站建设地址做网络推广的团队
  • 常州做企业网站的公司北京百度推广公司
  • wordpress 用户列表seo赚钱方式
  • 铜煤建设网站佛山网站建设排名
  • 溧阳做网站怎么创建自己的网址
  • html5网站建设网店怎么推广和宣传
  • wordpress外国主题首页优化排名
  • 邮箱企业邮箱seo是做什么工作内容
  • python网站开发环境自己怎么制作网页
  • 做电影网站需要告诉网络流量推广app
  • 机械做网站营销案例100例
  • 做个app好还是做网站好温州seo结算
  • 网站空间管理信息百度搜索结果优化
  • 网站前台修改知名品牌营销策划案例
  • 阿里云做网站的网站搜索查询
  • 有阿里空间怎么做网站每日新闻摘要30条
  • 做亚马逊需要的图片外链网站十大经典营销案例
  • 宁波做亚马逊网站培训机构不退钱最怕什么举报
  • 织梦后台 data移除后 网站无法打开下载百度app到手机上
  • 网站建设需要服务器么广州seo优化公司排名
  • 兼职做问卷调查的网站好新闻最新消息今天
  • ftp给网站做备份站长联盟
  • 家装博览会seo营销论文