Blame view

assets/global/plugins/sweetalert/js/finally.js 882 Bytes
6eb38308   Andy   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  /**
   * Promise.prototype.finally
   *
   * Pulled from https://github.com/domenic/promises-unwrapping/issues/18#issuecomment-57801572
   * @author @stefanpenner, @matthew-andrews
   */
  
  (function() {
  	// Get a handle on the global object
  	var local;
  	if (typeof global !== 'undefined') local = global;
  	else if (typeof window !== 'undefined' && window.document) local = window;
  	else local = self;
  
  	// It's replaced unconditionally to preserve the expected behavior
  	// in programs even if there's ever a native finally.
  	local.Promise.prototype['finally'] = function finallyPolyfill(callback) {
  		var constructor = this.constructor;
  
  		return this.then(function(value) {
  				return constructor.resolve(callback()).then(function() {
  					return value;
  				});
  			}, function(reason) {
  				return constructor.resolve(callback()).then(function() {
  					throw reason;
  				});
  			});
  	};
  }());