在浏览器中使用Q库 [英] Using Q library in browser
本文介绍了在浏览器中使用Q库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 Q
库( http:/ /documentup.com/kriskowal/q/ )在浏览器中。我想使用 RequireJS
来加载这个库,但我不知道如何做到这一点。我知道如何加载我自己的模块,但我不能用 Q
来做。它有一些功能:
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 idea how to do this. I know how to load my own module, but I can't do it with Q
. It has some function:
(function (definition) {
//some another code here***
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(definition);
如何加载 Q
然后在另一个模块中使用它?
How can I load Q
and then use it in another module?
推荐答案
您只需使用HTML中的脚本语句加载Q库
You can simply load the Q library using a script statement in your HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.1.0/q.js"></script>
然后您可以通过 Q
变量访问它,如下所示:
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);
});
见t他参加了 http://jsfiddle.net/Uesyd/1/
这篇关于在浏览器中使用Q库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文