【重点】JavaScript里的异步构造函数【兼容uni-app的app端】
参考:JS里的异步构造函数constructor(async_constructor = null) {/*** 功能:封装【自定义】的异步构造函数【同时兼容同步和异步,且兼容uni-app的APP端】* 特殊说明:*1、既然为异步构造函数,那么继承子类给this对象添加属性必须全部在asyncFunc方法实现!*2、在继承子类的构造函数中,this对象为一个promise对象,为
·
参考:JS里的异步构造函数
constructor(async_constructor = null) {
/**
* 功能:封装【自定义】的异步构造函数【同时兼容同步和异步,且兼容uni-app的APP端】
* 特殊说明:
* 1、既然为异步构造函数,那么继承子类给this对象添加属性必须全部在asyncFunc方法实现!
* 2、在继承子类的构造函数中,this对象为一个promise对象,为此asyncFunc方法内部才是this原始对象!
* 3、【注】使用异步构造函数实现【异步实例】JavaScript的语法提示不是很管用!
* 参数:
* asyncConstructor:需异步初始化的其他功能【继承子类为this添加属性,必须在此方法实现】
* 务必注意:
* 1、虽然JavaScript提供了一个异步构造函数的库【async-constructor】但是此库不兼容uni-app的【APP端】
*/
const _asyncEmptyFunc = async () => {
console.log("【>>==<<】正在使用【自定义】异步构函数函数中...");
};
const init = (async () => {
/**
* 1、这里必须实现一个await,否则会卡死!
*/
await _asyncEmptyFunc();
async_constructor && async_constructor();
delete this.then;
return this;
})();
this.then = init.then.bind(init);
}
更多推荐
已为社区贡献21条内容
所有评论(0)