Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// 例2
function getUserId() {
    return new Promise(function (resolve) {
        // 模拟异步操作
        window.setTimeout(function () {
            resolve(9876);
        }, 1000);
    });
}
getUserId().then(function (id) {
    console.log('do sth with', id);
}).then(function (id) {
    console.log('do sth else with', id);
});
function Promise(fn) {
    var value = null,
        deferreds = [];
        
    this.then = function (onFulfilled) {
        deferreds.push(onFulfilled);
        return this;
    };
    
    function resolve(value) {
        deferreds.forEach(function (deferred) {
            deferred(value);
        });
    }
    fn(resolve);
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers