普通函数与事件处理函数的区别?

小程序 文章 2021-01-30 11:21 513 0 全屏看文

AI助手支持GPT4.0

普通函数与事件处理函数的区别?What is the difference between ordinary functions and event handling functions?

普通函数与事件处理函数的区别?

为什么在page()中定义普通函数是无效的(或者叫无法定义函数?),而事件处理函数和生命周期函数是有效的?它们的本质区别是什么?

composeUrl: function (strreturn  "../" + str + "/" + str },  tapevt => {    // console.log(evt)    var pageUrl = composeUrl(evt.currentTarget.dataset.url)    // console.log(pageUrl)    wx.navigateTo({      url: pageUrl,    })}ReferenceError: composeUrl is not defined

Why is it invalid to define ordinary functions in page () (or it is impossible to define functions?), while event handling functions and life cycle functions are effective? What is the essential difference between them? Composeurl: function (STR) {return "/" + STR + "/" + STR},   tap: evt => {    //  console.log (evt)    var pageUrl = composeUrl( evt.currentTarget.dataset .url)    //  console.log (pageUrl)     wx.navigateTo ({      url: pageUrl,    })}ReferenceError: composeUrl is not defined

回答:

社区技术运营专员-CJiang:

你好,检查下是否是this指向的问题?

小黎:你要用this调用函数啊
跨商通:

js的基本概念还没搞清楚。

var pageUrl = this.composeUrl()


-EOF-

AI助手支持GPT4.0