【发布时间】:2019-10-15 08:00:33
【问题描述】:
我有几个关于类文件的问题。我有以下课程
class CouchController {
constructor(couchbase, config) {
// You may either pass couchbase and config as params, or import directly into the controller
this.cluster = new couchbase.Cluster(config.cluster);
this.cluster.authenticate(config.userid, config.password);
this.bucket = cluster.openBucket(config.bucket);
this.N1qlQuery = couchbase.N1qlQuery;
}
doSomeQuery(queryString, callback) {
this.bucket.manager().createPrimaryIndex(function() {
this.bucket.query(
this.N1qlQuery.fromString("SELECT * FROM bucketname WHERE $1 in interests LIMIT 1"),
[queryString],
callback(err, result)
)
});
}
}
我的问题是如何从类文件外部访问 doSomeQuery 函数?在内部访问该函数没有问题,但我需要能够从外部调用它。 我试过这样的事情
const CouchController = require("../controllers/CouchController")(couchbase, config)
let newTest = new CouchController
这样做 newTest 永远不会公开 doSomeQuery 方法。
还有什么方法的限制?它只能是一个简单的,还是可以是异步的并使用承诺等?
【问题讨论】:
-
newTest.doSomeQuery()?
标签: javascript node.js couchbase