Using Q library in browser

前端 未结 2 1737
忘掉有多难
忘掉有多难 2021-02-09 16:03

I need to use Q library (http://documentup.com/kriskowal/q/) in the browser. I would like to use RequireJS to load this library, but I don\'t have any

2条回答
  •  忘掉有多难
    2021-02-09 16:39

    You can simply load the Q library using a script statement in your HTML

    
    

    Then you can access it via the Q variable like so:

    function square(x) {
        return x * x;
    }
    function plus1(x) {
        return x + 1;
    }
    
    Q.fcall(function () {return 4;})
    .then(plus1)
    .then(square)
    .then(function(z) {
        alert("square of (value+1) = " + z);
    });
    

    See this running at http://jsfiddle.net/Uesyd/1/

提交回复
热议问题