(function () {
"use strict";
function Promise(executor) {
var self = this;
if (typeof executor !== "function") throw new TypeError("Promise resolver is not a function");
if (!(self instanceof Promise)) throw new TypeError("undefined is not a promise");
// 实例默认具备两个属性:state状态 result值
self.state = "pending";
self.result = undefined;
self.onFulfilledCallbacks = [];
self.onRejectedCallbacks = [];
// 修改实例的状态和值
var change = function change(state, result) {
// 状态一但不是pending,则不能再修改了
if (self.state !== "pending") return;
self.state = state;
self.result = res