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

改进事件处理函数未定义的错误提示 #2600

Closed
vimcaw opened this issue Mar 27, 2019 · 1 comment
Closed

改进事件处理函数未定义的错误提示 #2600

vimcaw opened this issue Mar 27, 2019 · 1 comment

Comments

@vimcaw
Copy link
Contributor

vimcaw commented Mar 27, 2019

目前触发一个事件,而事件处理函数未定义时,报错不太友好,希望能直接提示:事件处理函数 this.XXX 未定义。

例如:

<View onClick={this.undefinedHandler}>点击</View>

小程序报错:

VM9892:1 thirdScriptError
Cannot read property 'apply' of undefined; [Component] Event Listener Error @ components/Cell/index#(anonymous)
TypeError: Cannot read property 'apply' of undefined
    at z.obj.(anonymous function) [as gotoChooseCoupon] (http://127.0.0.1:36913/appservice/npm/@tarojs/taro-weapp/dist/index.js:3420:35)
    at z.P.u.(anonymous function).(anonymous function).u.addListener.capture (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:873213)
    at r.safeCallback (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:718316)
    at r.call (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:718209)
    at n (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:721206)
    at http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:721788
    at p (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:720753)
    at Function.c.dispatchEvent (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:721685)
    at Function.c.triggerEvent (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:721888)
    at n.w.triggerEvent (http://127.0.0.1:36913/appservice/__dev__/WAService.js:1:798212)

点进去发现是调用事件处理函数前未判断导致的:
image

搜索发现各个平台均是如此
Search · return scope[eventHandlerName].apply(callScope, realArgs);

@taro-bot
Copy link

taro-bot bot commented Mar 27, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@vimcaw vimcaw changed the title 改进事件绑定的错误提示 改进事件处理函数未定义的错误提示 Mar 27, 2019
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

1 participant