Browse Source

小程序中增加对promise.finally操作的支持 (#458)

Longmain 5 years ago
parent
commit
69de3b5418
2 changed files with 24 additions and 0 deletions
  1. 11 0
      litemall-wx/app.js
  2. 13 0
      renard-wx/app.js

+ 11 - 0
litemall-wx/app.js

@@ -4,6 +4,17 @@ var user = require('./utils/user.js');
 
 App({
   onLaunch: function() {
+    Promise.prototype.finally = function(callback){
+      let P = this.constructor;
+      return this.then(
+              value => {
+                   P.resolve(callback()).then(() => value)
+               },
+               reason => {
+                   P.resolve(callback()).then(() => { throw reason })
+               }
+           )
+    }
     const updateManager = wx.getUpdateManager();
     wx.getUpdateManager().onUpdateReady(function() {
       wx.showModal({

+ 13 - 0
renard-wx/app.js

@@ -4,7 +4,20 @@ var user = require('./utils/user.js');
 
 App({
   onLaunch: function() {
+    Promise.prototype.finally = function(callback){
+      let P = this.constructor;
+      return this.then(
+              value => {
+                   P.resolve(callback()).then(() => value)
+               },
+               reason => {
+                   P.resolve(callback()).then(() => { throw reason })
+               }
+           )
+    }
+
     const updateManager = wx.getUpdateManager();
+    
     wx.getUpdateManager().onUpdateReady(function() {
       wx.showModal({
         title: '更新提示',