我正在尝试理解以下代码,这些代码取自在feathersjs应用程序中创建的服务。
// Initializes the `users` service on path `/users`
const createService = require('feathers-knex');
const createModel = require('../../models/users.model');
const hooks = require('./users.hooks');
const filters = require('./users.filters');
module.exports = function () {
const app = this;
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
name: 'users',
Model,
paginate
};
// Initialize our service with any options it requires
app.use('/users', createService(options));
// Get our initialized service so that we can register hooks and filters
const service = app.service('users');
service.hooks(hooks);
if (service.filter) {
service.filter(filters);
}
};
然后按如下方式导入此文件:
// many requires..
const feathers = require('feathers');
// more requires
const services = require('./services');
// other requires
const app = feathers();
有人可以解释一下这行
const app = this
在创建服务的代码中做什么?
答案 0 :(得分:3)
它将this
的值分配给变量(井,常量),其名称比此更清楚地描述了该值。它旨在使维护人员更容易理解代码。