Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

提个小建议 #61

Open
renegadelyp opened this issue Jun 12, 2019 · 2 comments
Open

提个小建议 #61

renegadelyp opened this issue Jun 12, 2019 · 2 comments

Comments

@renegadelyp
Copy link

可不可以把那些可能为空的变量类型设为单一类型,由开发者自行判空呢?比如gameObject.parent,再比如egret3d.inputCollecter.getHoldKeys()...写一排if判空,只为能用一个值,有点...太闹心了...

image
image
我只是想取个键盘输入,但即便如此还是在报错...请问该用什么姿势才能取值呢?

@akdcl
Copy link
Contributor

akdcl commented Jun 13, 2019

可以开启 ts 严格模式来编写代码,就会舒适很多,那样你就会知道很多都不用判断,或者说什么应该判断什么无需判断,比如下面的声明,严格说明了可能返回 null,那没有声明的,就一定不会返回 null,完全无需判断。
https://github.com/egret-labs/egret3d/blob/master/core/egret3d/components/renderer/meshRenderer/MeshFilter.ts#L30

关于输入如何使用,可以看 egretpro 工程里自带的输入例子

@renegadelyp
Copy link
Author

renegadelyp commented Jun 13, 2019

那个...那这个该咋判断呢?就是取是否当前有按着“W”这个,因为我已经把我能想象到的都做if判断了,但依然在报错...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants