我对ES6类链接有疑问。我有一个如示例中的类。我想访问prefix()的值。我想在group(),get()和post()中使用prefix()的值。我该怎么办?
class Test {
constructor() {
this.prefixValue = null
}
get(path, controller) {
console.log(path, controller)
return this
}
post(path, controller) {
console.log(path, controller)
return this
}
group(cb) {
cb()
console.log(this.prefixValue)
return this
}
prefix(prefix) {
this.prefixValue = prefix
console.log(this.prefixValue)
return this
}
}
module.exports = new Test()
import Test from './router.js'
Test.get('/', 'IndexController.find')
Test.group(() => {
Test.get('/', 'MovieController.find')
Test.post('/', 'MovieController.create')
}).prefix('/movies')