Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <script src="http://static.jsbin.com/js/vendor/traceur.js"></script>
    <meta charset="utf-8">
    <title>Traceur ES6 Promise Object</title>
</head>
<body>
    <script>
        var squareOfPositiveNumber = function(number) {
            var myPromise = new Promise(function(resolve, reject) {
                if (number > 0) {
                    resolve(number * number);
                } else {
                    reject(new Error("Error:It is not a positive number."));
                }
            });
            return myPromise;
        };
        var squarePromise1 = squareOfPositiveNumber(5);
        squarePromise1.then(function(result) {
            console.log(result);
        });
        var squarePromise2 = squareOfPositiveNumber(-4);
        squarePromise2.then(null,
            function(error) {
                console.log(error.toString());
            });
    </script>
</body>
</html>
Output

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

Dismiss x
public
Bin info
saan1984pro
0viewers