需求:将所有页面的分享函数重写
const pageExtend = Page => {
return object => {
let currentPage = null
// 公共的onShareAppMessage事件处理函数
// console.log('object.onShareAppMessage.toString()', object.onShareAppMessage.toString())
if (object.onShareAppMessage && (object.onShareAppMessage.toString() == 'function onShareAppMessage() {}' || object.onShareAppMessage.toString() == 'function(){}' || object.onShareAppMessage.toString() == 'function (){}')) {
}
return Page(object)
}
}
// 获取原生Page
const originalPage = Page
// 定义一个新的Page,将原生Page传入Page扩展函数
Page = pageExtend(originalPage)
之前的object.onShareAppMessage.toString()结果为function onShareAppMessage() {},现在的安卓结果为function(){},苹果结果为function (){}