今天看代码看到了一处使用了关键字 with
以前并没有看过,经过一番搜索终于了解了其用法
结构
with(xxx){
code...
}
with可以帮助你在{}中省略写一些重复的代码,直接上例子
with(graphics){
clear();
beginFill(0x0f0,1);
drawRect(0,0,super.width,super.height);
endFill();
}
等价于
graphics.clear();
graphics.beginFill(0x0f0,1);
graphics.drawRect(0,0,super.width,super.height);
graphics.endFill();