diff --git a/docs/source/en/basics/extend.md b/docs/source/en/basics/extend.md index 8f62f97e02..65ff74d734 100644 --- a/docs/source/en/basics/extend.md +++ b/docs/source/en/basics/extend.md @@ -9,16 +9,16 @@ Egg.js is extensible and it provides multiple extension points to enhance the fu - Response - Helper -We could use the extension APIs to help with our developing, or extend the objects given above to enhance the functionality of egg as well while programming. +We could use the extension APIs to help us to develop, or extend the objects given above to enhance the functionality of egg as well while programming. ## Application -The object `app` is just the same aspect as the global application object in Koa. There should be only one `app` in your application, and it will be created by egg when the application is boot. +The object `app` is just the same aspect as the global application object in Koa. There should be only one `app` in your application, and it will be created by egg when the application is started. ### Access Method - `ctx.app` -- You can access the Application object by `this.app` in Controller, Middleware, Helper, Service. For instance, `this.app.config` will help you access the Config object. +- You can access the Application object by using `this.app` in Controller, Middleware, Helper, Service. For instance, `this.app.config` will help you access the Config object. - The `app` object would be injected into the entry function as the first argument in `app.js`, like this: ```js @@ -30,7 +30,7 @@ The object `app` is just the same aspect as the global application object in Koa ### How to extend -Egg will merge the object defined in `app/extend/application.js` with the prototype of Application object in Koa, then generate object `app` which is based on the extended prototype when application is boot. +Egg will merge the object defined in `app/extend/application.js` with the prototype of Application object in Koa, then generate object `app` which is based on the extended prototype when application is started. #### Extend Methods @@ -47,7 +47,7 @@ module.exports = { #### Extend Properties -Gernerally speaking, the calculation of properties only need to do once, therefore we have to do some cache, otherwise it will degrade performance of the app as too much calculation would be going to do when access those properties several times. +Generally speaking, the calculation of properties only need to be done once, therefore we have to do some cache, otherwise it will degrade performance of the app as too much calculation would be going to do when accessing those properties several times. So, it's recommended to use Symbol + Getter. @@ -71,7 +71,7 @@ module.exports = { ## Context -Context means the context in Koa, which is a **Request Level** object. That is to say, every request from client will gererate an Context instance. We usually write Context as `ctx` in short. Through all the doc, both Context and `ctx` means the context object in Koa. +Context means the context in Koa, which is a **Request Level** object. That is to say, every request from client will generate an Context instance. We usually write Context as `ctx` in short. In all the doc, both Context and `ctx` means the context object in Koa. ### Access Method @@ -98,7 +98,7 @@ module.exports = { #### Extend Properties -Gernerally speaking, the calculation of properties only need to do once, therefore we have to do some cache, otherwise it will degrade performance of the app as too much calculation would be going to do when access those properties several times. +Generally speaking, the calculation of properties only need to do once, therefore we have to do some cache, otherwise it will degrade performance of the app as too much calculation would be going to do when access those properties several times. So, it's recommended to use Symbol + Getter. @@ -130,13 +130,13 @@ Request object is the same as that in Koa, which is a **Request Level** object. ctx.request ``` -So many properties and methods in `ctx` can also be accessed in `request` object. For those properties and methods, it is just the same to access them eigher `ctx` or `request`, such as `ctx.url === ctx.request.url`. +So many properties and methods in `ctx` can also be accessed in `request` object. For those properties and methods, it is just the same to access them by using either `ctx` or `request`, such as `ctx.url === ctx.request.url`. Here are the properties and methods in `ctx` which can also be accessed by Request aliases: [Koa - Request aliases](http://koajs.com/#request-aliases) ### How to extend -Egg will merge the object defined in `app/extend/request.js` and the prototype of `request` object build in egg. And it will generate a `request` object which is based on the extended prototype when deal with request. +Egg will merge the object defined in `app/extend/request.js` and the prototype of `request` object built in egg. And it will generate a `request` object which is based on the extended prototype when deal with request. For instance, we could add a property `request.foo` in the following way: @@ -159,7 +159,7 @@ Response object is the same as that in Koa, which is a **Request Level** object. ctx.response ``` -So many properties and methods in `ctx` can also be accessed in `response` object. For those properties and methods, it is just the same to access them eigher `ctx` or `response`. For example `ctx.status = 404` is the same as `ctx.response.status = 404`. +So many properties and methods in `ctx` can also be accessed in `response` object. For those properties and methods, it is just the same to access them by using either `ctx` or `response`. For example `ctx.status = 404` is the same as `ctx.response.status = 404`. Here are the properties and methods in `ctx` which can also be accessed by Response aliases: [Koa Response aliases](http://koajs.com/#response-aliases) @@ -184,7 +184,7 @@ Then we can use the setter like this: `this.response.foo = 'bar';` Function Helper can provides some useful utility functions. -We can put some utility functions we use ofter into heper.js as an individual function. Then we can write the complex codes in JavaScript, avoiding to write them everywhere. Besides, such a simple function like Helper allows to write test case much easier. +We can put some utility functions we use ofter into helper.js as an individual function. Then we can write the complex codes in JavaScript, avoiding to write them everywhere. Besides, such a simple function like Helper allows to write test case much easier. Egg has had some build-in Helper functions. We can write our own Helper as well. @@ -233,4 +233,4 @@ module.exports = { This file will only be required under unittest environment. -Similarly, we could extend egg in this way for orther object,such as Application, Context, Request, Response and Helper. See more on [environment](./env.md) +Similarly, we could extend egg in this way for other object,such as Application, Context, Request, Response and Helper. See more on [environment](./env.md)